Running cppcheck 2.13.0 on attached file there is report about knownConditionTrueFalse. I think the report is wrong. cppcheck --enable=warning,style,performance,portability,missingInclude --suppress=missingIncludeSystem cppcheck-typeid.cc Checking cppcheck-typeid.cc ... cppcheck-typeid.cc:14:18: style: Condition 'type==typeid(int)' is always false [knownConditionTrueFalse] else if (type == typeid(int)) ^
Thanks - for the answer, and for the work with Cppcheck.
I have some cases where addition of just one more include path (leading to more header files being found) will lead to a huge increase in analysis time. No path to system headers, only my own headers. "Cppcheck is designed to check the code even without all headers". But I guess that without my headers the Class checks (missing member variable initialization etc.) are not possible?
When I run cppcheck 2.3 on the attached code I get Checking TernaryAstError2.cc ... TernaryAstError2.cc:20:28: error: AST broken, ternary operator missing operand(s) [internalAstError]
Hi, not sure if it is correct to reuse this one, but seem to be related. When I run cppcheck 2.2 on the code snip below I get AST broken, ternary operator missing operand(s) [internalAstError] Not there with cppcheck 2.1. #include <string> #include <vector> class A { public: A(const std::string& x, const std::vector<std::string>& y) {} }; void DoIt(const A& a) { } int main() { bool abc = true; DoIt({"X", {"Y", (abc == false ? "C" : "D")} }); return 0; }
Absolutely fair request. This example compiles and still exposed the error. #include <string> #include <vector> void DoIt(const std::string& name, std::vector<std::pair<std::string, std::string>>&& item) { } int main() { bool abc = true; DoIt("HH", { {"T", "123"}, {"ID", "456"}, {"State", "789"}, {"B", (abc) ? "UNDEF" : "DEF"} }); return 0; }
This give the error for me: int main() { {"B", (state == true) ? "UNDEF" : "DEF"}; } I know that it does not compile, but e.g. adding 'A b[] =' in front hide the error. I run cppcheck without any commandline options. Btw, I compiled cppcheck without Z3, since that did not compile in my environment (I think there is another discussion about that).
Running cppcheck 2.0 on lines of code like this: {"B", (state == true) ? "UNDEF" : "DEF"}; The output is AST broken, ternary operator missing operand(s) [internalAstError] Changing to {"B", state == true ? "UNDEF" : "DEF"}; the error is not there. It does not happen in cppcheck 1.90