Fixed #6222 (Missing varid for multiple braced initialized variables)
-> Fixed broken code in unit tests
This commit is contained in:
parent
079f495455
commit
3923618b8d
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
||||
}
|
||||
|
|
|
@ -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 ) ; "
|
||||
"} ;");
|
||||
|
|
|
@ -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<int> 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"
|
||||
|
|
Loading…
Reference in New Issue