static analyzer error in std::sort

I'm getting a static analysis warning on the following code. I don't think it could be my error, but I guess it's more likely a static analysis false positive than a C++ standard library bug. The warning says "Method called on moved-from object of type 'std::basic_string'". Tested in Xcode 26.5 RC. Reported as FB22735405.

#include <algorithm>
#include <string>
#include <vector>

#include <CoreFoundation/CoreFoundation.h>

template <
		class traits = std::char_traits<char>,
        class Allocator = std::allocator<char> >
struct UTF8StringLess
{
	bool	operator()(
		const std::basic_string<char, traits, Allocator>& inFirst,
		const std::basic_string<char, traits, Allocator>& inSecond ) const;
};

template<class traits, class Allocator>
inline bool	UTF8StringLess<traits, Allocator>::operator()(
		const std::basic_string<char, traits, Allocator>& inFirst,
		const std::basic_string<char, traits, Allocator>& inSecond ) const
{
	CFStringRef	theFirst = ::CFStringCreateWithCString( nullptr, inFirst.c_str(),
		kCFStringEncodingUTF8 );
	CFStringRef	theSecond = ::CFStringCreateWithCString( nullptr, inSecond.c_str(),
		kCFStringEncodingUTF8 );
	
	CFComparisonResult	compResult = ::CFStringCompare( theFirst, theSecond,
		kCFCompareCaseInsensitive );
	bool	isLess = (compResult == kCFCompareLessThan);
	
	::CFRelease( theFirst );
	::CFRelease( theSecond );
	
	return isLess;
}


int main(int argc, const char * argv[])
{
	std::vector<std::string> names{ "obey", "Zorro", "can" };
	
	std::sort( names.begin(), names.end(), UTF8StringLess() );
	
	return EXIT_SUCCESS;
}

Thanks for the post, that looks like a clang issue to me. Is that for line 22? You can suppress the warning locally so it doesn't clutter your build with #ifndef __clang_analyzer__

There are many awesome C++ engineers here that I'm sure they'll be able to figure it out, but seems an error from clang. Or is the warning triggered by the cplusplus.Move?

Can you post the output box warnings and errors?

Thanks Albert
  Worldwide Developer Relations.

@DTS Engineer The error points to line 24. I'm not sure what you mean by "output box", but here is a screenshot of the Issue Navigator.

For what it's worth, I produced a shorter program that no longer depends on CoreFoundation but still produces the same static analyzer warning.

#include <algorithm>
#include <string>
#include <strings.h>
#include <vector>

int main(int argc, const char * argv[])
{
	std::vector<std::string> names{ "obey", "Zorro", "can" };
	
	std::sort( names.begin(), names.end(),
		[](const std::string& a, const std::string& b)
		{
			return strcasecmp( a.c_str(), b.c_str() ) < 0;
		} );
	
	return EXIT_SUCCESS;
}

Thank you for providing additional information. And definitely thanks for providing the focus sample reproducing the issue.

May I request that you file a bug so that I can route it correctly to that team?

Please include the project not just the code so they can use the project file to reproduce it when creating the bug, you can upload the project on a zip file.

Once you open the bug report, please post the FB number here for my reference.

If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?

Thanks again for providing everything!

Albert
  Worldwide Developer Relations.

As I said in my first post, I already filed a bug, FB22735405. I have updated it with the shorter code.

@JWWalker Thanks for doing that. I'll make sure to the bug gets to the correct team. Appreciate providing a better project.

Albert
  Worldwide Developer Relations.

static analyzer error in std::sort
 
 
Q