From 3923618b8dd2a9f17ead38e81905dc52743ac48c Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Thu, 16 Oct 2014 20:46:44 +0200 Subject: [PATCH] Fixed #6222 (Missing varid for multiple braced initialized variables) -> Fixed broken code in unit tests --- lib/tokenize.cpp | 10 ++++++++++ test/testconstructors.cpp | 14 ++------------ test/testother.cpp | 16 ++++++++-------- test/testsimplifytypedef.cpp | 4 ++-- test/testvarid.cpp | 6 ++++-- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a364e7d35..2a0bdf93a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5527,6 +5527,16 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_ if (tok2 && tok2->str() == ";") tok2 = nullptr; } + } + + // brace initialization + else if (Token::Match(varName, "%var% {")) { + tok2 = varName->next(); + tok2 = tok2->link(); + if (tok2) + tok2 = tok2->next(); + if (tok2 && tok2->str() != ",") + tok2 = nullptr; } else tok2 = nullptr; } else { diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 62e546952..f286756f7 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -387,22 +387,12 @@ private: " int z{0};\n" " int (*pf[2])(){nullptr, nullptr};\n" " int a[2][3] = {{1,2,3},{4,5,6}};\n" - " int d, e{3};\n" - "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", errout.str()); - - check("class Fred {\n" - "public:\n" - " Fred() {}\n" - "private:\n" " int b{1}, c{2};\n" " int d, e{3};\n" " int f{4}, g;\n" "};"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n" - "[test.cpp:3]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", - "[test.cpp:3]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", - errout.str()); // fails due to missing varid + ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n" + "[test.cpp:3]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str()); } void simple12() { // ticket #4620 diff --git a/test/testother.cpp b/test/testother.cpp index 039113805..4f207f111 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5942,37 +5942,37 @@ private: ASSERT_EQUALS("", errout.str()); // avoid crash with pointer variable - for local variable on stack as well - see #4801 - check("void foo {\n" + check("void foo() {\n" " int *cp;\n" " if ( pipe (cp) == -1 ) {\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // test with unknown variable - check("void foo {\n" + check("void foo() {\n" " if ( pipe (cp) == -1 ) {\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // avoid crash with pointer variable - for local variable on stack as well - see #4801 - check("void foo {\n" + check("void foo() {\n" " int *cp;\n" " if ( pipe (cp) == -1 ) {\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // test with unknown variable - check("void foo {\n" + check("void foo() {\n" " if ( pipe (cp) == -1 ) {\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 695ebb903..a0a7c080e 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -1599,13 +1599,13 @@ private: } void simplifyTypedef57() { // ticket #1846 - const char code[] = "void foo {\n" + const char code[] = "void foo() {\n" " typedef int A;\n" " A a = A(1) * A(2);\n" "};\n"; // The expected result.. - const std::string expected("void foo { " + const std::string expected("void foo ( ) { " "" "int a ; a = int ( 1 ) * int ( 2 ) ; " "} ;"); diff --git a/test/testvarid.cpp b/test/testvarid.cpp index e52456734..ffb490a95 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -1851,11 +1851,13 @@ private: "1: int i@1 { 1 } ;\n" "2: std :: vector < int > vec@2 { 1 , 2 , 3 } ;\n" "3: namespace n { int z@3 ; } ;\n" - "4: int & j@4 { i@1 } ;\n", + "4: int & j@4 { i@1 } ;\n" + "5: int k@5 { 1 } ; int l@6 { 2 } ;\n", tokenize("int i{1};\n" "std::vector vec{1, 2, 3};\n" "namespace n { int z; };\n" - "int& j{i};\n")); + "int& j{i};\n" + "int k{1}, l{2};")); // #6030 ASSERT_EQUALS("\n\n##file 0\n"