The full context of the error message is in checkstl.cpp, which notes that one should use compare if comparing to 0 or compare to std::string::npos if looking for no matches.
In the above example, a string is checked for existence of a substring in an unknown but bounded location (starts within the first 12 characters), so I think it's a valid use of the API. I'm planning to suppress this warning but wanted to report it as a false positive.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
0c113d65.cpp:5:5: performance: Inefficientusageofstring::find()incondition; string::starts_with() could be faster. [stlIfStrFind]if(line.find(" GL_EXTENSIONS =")<12)
The following code gets flagged with a stlIfStrFind error "Inefficient usage of string::find() in condition; string::compare() would be faster."
The full context of the error message is in checkstl.cpp, which notes that one should use
compare
if comparing to0
or compare tostd::string::npos
if looking for no matches.In the above example, a string is checked for existence of a substring in an unknown but bounded location (starts within the first 12 characters), so I think it's a valid use of the API. I'm planning to suppress this warning but wanted to report it as a false positive.
v2.3 reports
on this completed snippet:
Since starts_with() can't be used in this situation, I think it's a FP.
Ticket is here: https://trac.cppcheck.net/ticket/10153