-
What language is this for?
C++11 thru C++17 -
Which rule?
cpp:S5566 -
Why do you believe it’s a false-positive?
According to std::all_of, std::any_of, std::none_of - cppreference.com, certain STL container algorithms are not marked asconstexpr
functions in C++ versions prior to 20.
An exception should be applied for this rule if it’s analyzing aconstexpr
function on C++ versions prior to 20 (C++11 thru C++17) -
Are you using…?
SonarLint on VSCode -
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
constexpr bool AllDigits_OK(const std::vector<char>& vect)
{
for (const auto& vChar : vect) {
if (vChar < '0' || vChar > '9')
return false;
}
return true;
}
/* Fails to compile with the following error: arm-linux-gnueabihf-g++ 8.3.0 with flag -std=c++17
error: call to non-'constexpr' function 'bool std::all_of(_IIter, _IIter, _Predicate)
[with _IIter = __gnu_cxx::__normal_iterator<const char*, std::vector<char> >;
_Predicate = AllDigits_KO(const std::vector<char>&)::<lambda(char)>]'
return std::all_of(vect.begin(), vect.end(), [](const char vChar) {
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return vChar >= '0' && vChar <= '9';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
});
*/
constexpr bool AllDigits_KO(const std::vector<char>& vect)
{
return std::all_of(vect.begin(), vect.end(), [](const char vChar) {
return vChar >= '0' && vChar <= '9';
});
}