The following code:
#include <string> void test(std::string const& a, std::string const& b) { if (a.empty() && b.empty()) { } else if (a.empty() == false && b.empty() == false) // False positives { } if (a.empty() && b.empty()) { } else if (!a.empty() && !b.empty()) // This is fine { } }
produces the following warnings:
Checking test.cpp ... test.cpp:8:22: style: Condition 'a.empty()==false' is always true [knownConditionTrueFalse] else if (a.empty() == false && b.empty() == false) ^ test.cpp:5:14: note: Assuming that condition 'a.empty()' is not redundant if (a.empty() && b.empty()) ^ test.cpp:8:22: note: Condition 'a.empty()==false' is always true else if (a.empty() == false && b.empty() == false) ^ test.cpp:8:44: style: Condition 'b.empty()==false' is always true [knownConditionTrueFalse] else if (a.empty() == false && b.empty() == false) ^ test.cpp:5:27: note: Assuming that condition 'b.empty()' is not redundant if (a.empty() && b.empty()) ^ test.cpp:8:44: note: Condition 'b.empty()==false' is always true else if (a.empty() == false && b.empty() == false) ^
Note that turning the .empty() == false calls into using the not operator like !a.empty() does not produce the warnings.
.empty() == false
!a.empty()
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11548
Log in to post a comment.
The following code:
produces the following warnings:
Note that turning the
.empty() == false
calls into using the not operator like!a.empty()
does not produce the warnings.Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11548