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;
}
0
0
5