Uninitvar: Made checking experimental

This commit is contained in:
Daniel Marjamäki 2011-11-20 15:19:56 +01:00
parent 11dd3c09ce
commit b92959809c
3 changed files with 36 additions and 32 deletions

View File

@ -27,7 +27,8 @@
// Register this check class (by creating a static instance of it) // Register this check class (by creating a static instance of it)
namespace { namespace {
CheckUninitVar instance; // The ExecutionPath framework doesn't work as well as I wanted
//CheckUninitVar instance;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -1018,6 +1019,9 @@ void CheckUninitVar::saveAnalysisData(const std::set<std::string> &data) const
void CheckUninitVar::executionPaths() void CheckUninitVar::executionPaths()
{ {
if (!_settings->experimental)
return;
// check if variable is accessed uninitialized.. // check if variable is accessed uninitialized..
{ {
// no writing if multiple threads are used (TODO: thread safe analysis?) // no writing if multiple threads are used (TODO: thread safe analysis?)

View File

@ -157,6 +157,7 @@ private:
Settings settings; Settings settings;
settings._inlineSuppressions = true; settings._inlineSuppressions = true;
settings.experimental = true;
if (!suppression.empty()) if (!suppression.empty())
settings.nomsg.addSuppressionLine(suppression); settings.nomsg.addSuppressionLine(suppression);
@ -171,18 +172,16 @@ private:
void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) { void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) {
// check to make sure the appropriate error is present // check to make sure the appropriate error is present
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a = 4 / 0;\n"
" a++;\n"
"}\n", "}\n",
""); "");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero\n", errout.str());
// suppress uninitvar globally // suppress uninitvar globally
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a = 4 / 0;\n"
" a++;\n"
"}\n", "}\n",
"uninitvar"); "zerodiv");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// suppress uninitvar globally, without error present // suppress uninitvar globally, without error present
@ -190,15 +189,15 @@ private:
" int a;\n" " int a;\n"
" b++;\n" " b++;\n"
"}\n", "}\n",
"uninitvar"); "zerodiv");
ASSERT_EQUALS("[*]: (information) Unmatched suppression: uninitvar\n", errout.str()); ASSERT_EQUALS("[*]: (information) Unmatched suppression: zerodiv\n", errout.str());
// suppress uninitvar for this file only // suppress uninitvar for this file only
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a = 4 / 0;\n"
" a++;\n" " a++;\n"
"}\n", "}\n",
"uninitvar:test.cpp"); "zerodiv:test.cpp");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// suppress uninitvar for this file only, without error present // suppress uninitvar for this file only, without error present
@ -206,13 +205,13 @@ private:
" int a;\n" " int a;\n"
" b++;\n" " b++;\n"
"}\n", "}\n",
"uninitvar:test.cpp"); "zerodiv:test.cpp");
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar\n", errout.str()); ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: zerodiv\n", errout.str());
// suppress all for this file only // suppress all for this file only
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" a++;\n" " a = 4 / 0;\n"
"}\n", "}\n",
"*:test.cpp"); "*:test.cpp");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -228,24 +227,24 @@ private:
// suppress uninitvar for this file and line // suppress uninitvar for this file and line
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" a++;\n" " a = 4 / 0;\n"
"}\n", "}\n",
"uninitvar:test.cpp:3"); "zerodiv:test.cpp:3");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// suppress uninitvar for this file and line, without error present // suppress uninitvar for this file and line, without error present
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" b++;\n" " a = 4;\n"
"}\n", "}\n",
"uninitvar:test.cpp:3"); "zerodiv:test.cpp:3");
ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: uninitvar\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: zerodiv\n", errout.str());
// suppress uninitvar inline // suppress uninitvar inline
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" // cppcheck-suppress uninitvar\n" " // cppcheck-suppress zerodiv\n"
" a++;\n" " a = 4 / 0;\n"
"}\n", "}\n",
""); "");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -253,9 +252,9 @@ private:
// suppress uninitvar inline // suppress uninitvar inline
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" // cppcheck-suppress uninitvar\n" " // cppcheck-suppress zerodiv\n"
"\n" "\n"
" a++;\n" " a = 4 / 0;\n"
"}\n", "}\n",
""); "");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -263,8 +262,8 @@ private:
// suppress uninitvar inline // suppress uninitvar inline
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" /* cppcheck-suppress uninitvar */\n" " /* cppcheck-suppress zerodiv */\n"
" a++;\n" " a = 4 / 0;\n"
"}\n", "}\n",
""); "");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -272,9 +271,9 @@ private:
// suppress uninitvar inline // suppress uninitvar inline
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" /* cppcheck-suppress uninitvar */\n" " /* cppcheck-suppress zerodiv */\n"
"\n" "\n"
" a++;\n" " a = 4 / 0;\n"
"}\n", "}\n",
""); "");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -282,11 +281,11 @@ private:
// suppress uninitvar inline, without error present // suppress uninitvar inline, without error present
(this->*check)("void f() {\n" (this->*check)("void f() {\n"
" int a;\n" " int a;\n"
" // cppcheck-suppress uninitvar\n" " // cppcheck-suppress zerodiv\n"
" b++;\n" " a = 4;\n"
"}\n", "}\n",
""); "");
ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: uninitvar\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: zerodiv\n", errout.str());
} }
void suppressionsSettings() { void suppressionsSettings() {
@ -302,12 +301,12 @@ private:
"}\n", "}\n",
"void f() {\n" "void f() {\n"
" int a;\n" " int a;\n"
" a++;\n" " a = 4 / 0;\n"
"}\n", "}\n",
}; };
// suppress uninitvar for this file and line // suppress uninitvar for this file and line
checkSuppression(names, codes, "uninitvar:xyz.cpp:3"); checkSuppression(names, codes, "zerodiv:xyz.cpp:3");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }

View File

@ -55,6 +55,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.experimental = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);