Hello,
We used cppcheck to test the example provided by itself, but there is no error that should exist. What is the cause of this?
I sincerely hope to get your reply.
Here is the file without error:
testbool.cpp #line 726
testbool.cpp #line 756
testfunction.cpp #line 842
testother.cpp #line 2696
testother.cpp #line 3325
testother.cpp #line 4359
testother.cpp #line 4688
testsizeof.cpp #line 410
testsizeof.cpp #line 390
testother.cpp #line 5329
E.g:
<error id="suspiciousCase" severity="warning" msg="Found suspicious case label in switch(). Operator '||' probably doesn't work as intended." verbose="Using an operator like '||' in a case label is suspicious. Did you intend to use a bitwise operator, multiple case labels or if/else instead?" cwe="398" inconclusive="true"/>
code:
void function() { //This is the code we tested
switch(a) {
case a && b:
function();
case (a||b):
function();
case a||b:
function();
}
}
testother.cpp #line 2696 //This is the source code of cppcheck
check("void foo() {\n"
" switch(a) {\n"
" case A&&B:\n"
" foo();\n"
" case (A||B):\n"
" foo();\n"
" case A||B:\n"
" foo();\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended.\n"
"[test.cpp:5]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended.\n"
"[test.cpp:7]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended.\n", errout.str());
Last edit: 顾涛明 2018-04-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you very much. I didn't add --inconclusive, but I still have a question as to why the official example also adds --inconclusive, as if this is an indeterminate parameter. Why is it necessary to add this parameter correctly?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
We used cppcheck to test the example provided by itself, but there is no error that should exist. What is the cause of this?
I sincerely hope to get your reply.
Here is the file without error:
testbool.cpp #line 726
testbool.cpp #line 756
testfunction.cpp #line 842
testother.cpp #line 2696
testother.cpp #line 3325
testother.cpp #line 4359
testother.cpp #line 4688
testsizeof.cpp #line 410
testsizeof.cpp #line 390
testother.cpp #line 5329
E.g:
<error id="suspiciousCase" severity="warning" msg="Found suspicious case label in switch(). Operator '||' probably doesn't work as intended." verbose="Using an operator like '||' in a case label is suspicious. Did you intend to use a bitwise operator, multiple case labels or if/else instead?" cwe="398" inconclusive="true"/>
code:
void function() { //This is the code we tested
switch(a) {
case a && b:
function();
case (a||b):
function();
case a||b:
function();
}
}
testother.cpp #line 2696 //This is the source code of cppcheck
check("void foo() {\n"
" switch(a) {\n"
" case A&&B:\n"
" foo();\n"
" case (A||B):\n"
" foo();\n"
" case A||B:\n"
" foo();\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended.\n"
"[test.cpp:5]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended.\n"
"[test.cpp:7]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended.\n", errout.str());
Last edit: 顾涛明 2018-04-24
How do you run cppcheck? Try something like:
Thank you very much. I didn't add --inconclusive, but I still have a question as to why the official example also adds --inconclusive, as if this is an indeterminate parameter. Why is it necessary to add this parameter correctly?