Closed
Description
Description of the false positive
I'm using a meta-programming trick that reduces the number of overloads by sorting the arguments to a function like so:
template <typename TString1, typename TString2>
typename std::enable_if<TString1::typeSortKey <= TString2::typeSortKey, int>::type
stringCompare(TString1 s1, TString2 s2) {
// IMPLEMENTATION
}
template <typename TString1, typename TString2>
typename std::enable_if<(TString1::typeSortKey > TString2::typeSortKey), int>::type
stringCompare(TString1 s1, TString2 s2) {
return -stringCompare(s2, s1);
}
As you can see, this code uses the same implementation even if the arguments are reversed.
The alert "Self Comparison" triggers on the expression TString1::typeSortKey <= TString2::typeSortKey
.
Indeed, it can be a self-comparison if TString1
and TString2
are the same type, but in the general case, it's not.
URL to the alert on the project page on LGTM.com