Skip to content

Instantly share code, notes, and snippets.

@orbitcowboy
Last active August 29, 2015 14:05
Show Gist options
  • Save orbitcowboy/412d13e534b21e56c87a to your computer and use it in GitHub Desktop.
Save orbitcowboy/412d13e534b21e56c87a to your computer and use it in GitHub Desktop.
A program to generate test cases for ticket (http://trac.cppcheck.net/ticket/6074)
#include <iostream>
#include <string>
int main()
{
const std::string operand[6] = { "a", "!(a)", "!(!a)", "~(a)", "~(!a)", "!(~a)" };
const std::string op[2] = { "==" , "!=" };
std::cout << "void f(bool a)\n"
"{\n";
for(unsigned int l = 0; l < 6; ++l)
for(unsigned int m = 0; m < 2; ++m)
for(unsigned int k = 0; k < 6; ++k)
{
std::cout << " if( ";
std::cout << operand[l] << " ";
std::cout << op[m] << " ";
std::cout << operand[k] << " ";
std::cout << ") {}\n";
}
std::cout << "}\n";
return 1;
}
/* Reveal false negatives of cppcheck (see ticket http://trac.cppcheck.net/ticket/6074)
$ g++ generateExpression.cpp && ./a.out > t.cpp && cppcheck --enable=all t.cpp
martin@ubuntu:~/projects_new/schnipsl$ cppcheck --enable=all t.cpp
Checking t.cpp...
[t.cpp:3] -> [t.cpp:3]: (style) Same expression on both sides of '=='.
[t.cpp:9] -> [t.cpp:9]: (style) Same expression on both sides of '!='.
[t.cpp:16] -> [t.cpp:16]: (style) Same expression on both sides of '=='.
[t.cpp:22] -> [t.cpp:22]: (style) Same expression on both sides of '!='.
[t.cpp:29] -> [t.cpp:29]: (style) Same expression on both sides of '=='.
[t.cpp:35] -> [t.cpp:35]: (style) Same expression on both sides of '!='.
[t.cpp:42] -> [t.cpp:42]: (style) Same expression on both sides of '=='.
[t.cpp:48] -> [t.cpp:48]: (style) Same expression on both sides of '!='.
[t.cpp:55] -> [t.cpp:55]: (style) Same expression on both sides of '=='.
[t.cpp:61] -> [t.cpp:61]: (style) Same expression on both sides of '!='.
[t.cpp:68] -> [t.cpp:68]: (style) Same expression on both sides of '=='.
[t.cpp:74] -> [t.cpp:74]: (style) Same expression on both sides of '!='.
Checking usage of global functions..
[t.cpp:1]: (style) The function 'f' is never used.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment