Fixed false positive uninitMemberVar with member function of template (#7205)

This commit is contained in:
PKEuS 2016-01-30 20:15:56 +01:00
parent 23ad881c64
commit 5d9f275ff8
2 changed files with 23 additions and 2 deletions

View File

@ -546,8 +546,8 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
assignVar(ftok->next()->varId(), scope, usage);
}
// Before a new statement there is "[{};()=[]"
if (! Token::Match(ftok, "[{};()=[]"))
// Before a new statement there is "[{};()=[]" or ::
if (! Token::Match(ftok, "{|}|;|(|)|=|[|::"))
continue;
if (Token::simpleMatch(ftok, "( !"))

View File

@ -106,6 +106,8 @@ private:
TEST_CASE(initvar_alias); // #6921
TEST_CASE(initvar_templateMember); // #7205
TEST_CASE(operatorEqSTL);
TEST_CASE(uninitVar1);
@ -1439,6 +1441,25 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'S::a' is not initialized in the constructor.\n", errout.str());
}
void initvar_templateMember() {
check("template<int n_>\n"
"struct Wrapper {\n"
" static void foo(int * x) {\n"
" for (int i(0); i <= n_; ++i)\n"
" x[i] = 5;\n"
" }\n"
"};\n"
"class A {\n"
"public:\n"
" static constexpr int dim = 5;\n"
" int x[dim + 1];\n"
" A() {\n"
" Wrapper<dim>::foo(x);\n"
" }\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void operatorEqSTL() {
check("class Fred\n"
"{\n"