Skip to content

Commit 5d9f275

Browse files
committed
Fixed false positive uninitMemberVar with member function of template (#7205)
1 parent 23ad881 commit 5d9f275

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/checkclass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
546546
assignVar(ftok->next()->varId(), scope, usage);
547547
}
548548

549-
// Before a new statement there is "[{};()=[]"
550-
if (! Token::Match(ftok, "[{};()=[]"))
549+
// Before a new statement there is "[{};()=[]" or ::
550+
if (! Token::Match(ftok, "{|}|;|(|)|=|[|::"))
551551
continue;
552552

553553
if (Token::simpleMatch(ftok, "( !"))

test/testconstructors.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class TestConstructors : public TestFixture {
106106

107107
TEST_CASE(initvar_alias); // #6921
108108

109+
TEST_CASE(initvar_templateMember); // #7205
110+
109111
TEST_CASE(operatorEqSTL);
110112

111113
TEST_CASE(uninitVar1);
@@ -1439,6 +1441,25 @@ class TestConstructors : public TestFixture {
14391441
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'S::a' is not initialized in the constructor.\n", errout.str());
14401442
}
14411443

1444+
void initvar_templateMember() {
1445+
check("template<int n_>\n"
1446+
"struct Wrapper {\n"
1447+
" static void foo(int * x) {\n"
1448+
" for (int i(0); i <= n_; ++i)\n"
1449+
" x[i] = 5;\n"
1450+
" }\n"
1451+
"};\n"
1452+
"class A {\n"
1453+
"public:\n"
1454+
" static constexpr int dim = 5;\n"
1455+
" int x[dim + 1];\n"
1456+
" A() {\n"
1457+
" Wrapper<dim>::foo(x);\n"
1458+
" }\n"
1459+
"};");
1460+
ASSERT_EQUALS("", errout.str());
1461+
}
1462+
14421463
void operatorEqSTL() {
14431464
check("class Fred\n"
14441465
"{\n"

0 commit comments

Comments
 (0)