From 5d9f275ff8fce129282c65e4597e7f8af677c607 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 30 Jan 2016 20:15:56 +0100 Subject: [PATCH] Fixed false positive uninitMemberVar with member function of template (#7205) --- lib/checkclass.cpp | 4 ++-- test/testconstructors.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index c4e8f9fa0..63675beb6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -546,8 +546,8 @@ void CheckClass::initializeVarList(const Function &func, std::listnext()->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, "( !")) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index ba8d8a95c..695030d88 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -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\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::foo(x);\n" + " }\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void operatorEqSTL() { check("class Fred\n" "{\n"