Uninitvar: Made checking experimental
This commit is contained in:
parent
11dd3c09ce
commit
b92959809c
|
@ -27,7 +27,8 @@
|
|||
|
||||
// Register this check class (by creating a static instance of it)
|
||||
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()
|
||||
{
|
||||
if (!_settings->experimental)
|
||||
return;
|
||||
|
||||
// check if variable is accessed uninitialized..
|
||||
{
|
||||
// no writing if multiple threads are used (TODO: thread safe analysis?)
|
||||
|
|
|
@ -157,6 +157,7 @@ private:
|
|||
|
||||
Settings settings;
|
||||
settings._inlineSuppressions = true;
|
||||
settings.experimental = true;
|
||||
if (!suppression.empty())
|
||||
settings.nomsg.addSuppressionLine(suppression);
|
||||
|
||||
|
@ -171,18 +172,16 @@ private:
|
|||
void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) {
|
||||
// check to make sure the appropriate error is present
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
" int a = 4 / 0;\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
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
" int a = 4 / 0;\n"
|
||||
"}\n",
|
||||
"uninitvar");
|
||||
"zerodiv");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// suppress uninitvar globally, without error present
|
||||
|
@ -190,15 +189,15 @@ private:
|
|||
" int a;\n"
|
||||
" b++;\n"
|
||||
"}\n",
|
||||
"uninitvar");
|
||||
ASSERT_EQUALS("[*]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
||||
"zerodiv");
|
||||
ASSERT_EQUALS("[*]: (information) Unmatched suppression: zerodiv\n", errout.str());
|
||||
|
||||
// suppress uninitvar for this file only
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" int a = 4 / 0;\n"
|
||||
" a++;\n"
|
||||
"}\n",
|
||||
"uninitvar:test.cpp");
|
||||
"zerodiv:test.cpp");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// suppress uninitvar for this file only, without error present
|
||||
|
@ -206,13 +205,13 @@ private:
|
|||
" int a;\n"
|
||||
" b++;\n"
|
||||
"}\n",
|
||||
"uninitvar:test.cpp");
|
||||
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
||||
"zerodiv:test.cpp");
|
||||
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: zerodiv\n", errout.str());
|
||||
|
||||
// suppress all for this file only
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
" a = 4 / 0;\n"
|
||||
"}\n",
|
||||
"*:test.cpp");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -228,24 +227,24 @@ private:
|
|||
// suppress uninitvar for this file and line
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
" a = 4 / 0;\n"
|
||||
"}\n",
|
||||
"uninitvar:test.cpp:3");
|
||||
"zerodiv:test.cpp:3");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// suppress uninitvar for this file and line, without error present
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" b++;\n"
|
||||
" a = 4;\n"
|
||||
"}\n",
|
||||
"uninitvar:test.cpp:3");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: uninitvar\n", errout.str());
|
||||
"zerodiv:test.cpp:3");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: zerodiv\n", errout.str());
|
||||
|
||||
// suppress uninitvar inline
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" // cppcheck-suppress uninitvar\n"
|
||||
" a++;\n"
|
||||
" // cppcheck-suppress zerodiv\n"
|
||||
" a = 4 / 0;\n"
|
||||
"}\n",
|
||||
"");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -253,9 +252,9 @@ private:
|
|||
// suppress uninitvar inline
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" // cppcheck-suppress uninitvar\n"
|
||||
" // cppcheck-suppress zerodiv\n"
|
||||
"\n"
|
||||
" a++;\n"
|
||||
" a = 4 / 0;\n"
|
||||
"}\n",
|
||||
"");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -263,8 +262,8 @@ private:
|
|||
// suppress uninitvar inline
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" /* cppcheck-suppress uninitvar */\n"
|
||||
" a++;\n"
|
||||
" /* cppcheck-suppress zerodiv */\n"
|
||||
" a = 4 / 0;\n"
|
||||
"}\n",
|
||||
"");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -272,9 +271,9 @@ private:
|
|||
// suppress uninitvar inline
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" /* cppcheck-suppress uninitvar */\n"
|
||||
" /* cppcheck-suppress zerodiv */\n"
|
||||
"\n"
|
||||
" a++;\n"
|
||||
" a = 4 / 0;\n"
|
||||
"}\n",
|
||||
"");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -282,11 +281,11 @@ private:
|
|||
// suppress uninitvar inline, without error present
|
||||
(this->*check)("void f() {\n"
|
||||
" int a;\n"
|
||||
" // cppcheck-suppress uninitvar\n"
|
||||
" b++;\n"
|
||||
" // cppcheck-suppress zerodiv\n"
|
||||
" a = 4;\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() {
|
||||
|
@ -302,12 +301,12 @@ private:
|
|||
"}\n",
|
||||
"void f() {\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
" a = 4 / 0;\n"
|
||||
"}\n",
|
||||
};
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
errout.str("");
|
||||
|
||||
Settings settings;
|
||||
settings.experimental = true;
|
||||
|
||||
// Tokenize..
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
|
|
Loading…
Reference in New Issue