Fix uniform init in out-of-class ctor-initer
This commit is contained in:
parent
405a1fba11
commit
a75872a15e
|
@ -2931,15 +2931,15 @@ void Tokenizer::setVarId()
|
|||
}
|
||||
|
||||
// constructor with initializer list
|
||||
if (Token::Match(tok2, ") : %name% (")) {
|
||||
if (Token::Match(tok2, ") : %name% (|{")) {
|
||||
Token *tok3 = tok2;
|
||||
do {
|
||||
Token *vartok = tok3->tokAt(2);
|
||||
if (varlist[classname].find(vartok->str()) != varlist[classname].end())
|
||||
vartok->varId(varlist[classname][vartok->str()]);
|
||||
tok3 = tok3->linkAt(3);
|
||||
} while (Token::Match(tok3, ") [:,] %name% ("));
|
||||
if (Token::simpleMatch(tok3, ") {")) {
|
||||
} while (Token::Match(tok3, ")|} [:,] %name% (|{"));
|
||||
if (Token::Match(tok3, ")|} {")) {
|
||||
setVarIdClassFunction(classname, tok2, tok3->next()->link(), varlist[classname], &structMembers, &_varId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6007,6 +6007,22 @@ private:
|
|||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Member variable 's' is initialized by itself.\n", errout.str());
|
||||
|
||||
checkSelfInitialization("class Fred {\n"
|
||||
" int x;\n"
|
||||
" Fred(int x);\n"
|
||||
"};\n"
|
||||
"Fred::Fred(int x) : x(x) { }\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSelfInitialization("class Fred {\n"
|
||||
" int x;\n"
|
||||
" Fred(int x);\n"
|
||||
"};\n"
|
||||
"Fred::Fred(int x) : x{x} { }\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSelfInitialization("class Fred {\n"
|
||||
" std::string s;\n"
|
||||
" Fred(const std::string& s) : s(s) {\n"
|
||||
|
@ -6014,6 +6030,13 @@ private:
|
|||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSelfInitialization("class Fred {\n"
|
||||
" std::string s;\n"
|
||||
" Fred(const std::string& s) : s{s} {\n"
|
||||
" }\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSelfInitialization("struct Foo : Bar {\n"
|
||||
" int i;\n"
|
||||
" Foo(int i)\n"
|
||||
|
|
|
@ -156,6 +156,7 @@ private:
|
|||
TEST_CASE(varidclass15); // initializer list
|
||||
TEST_CASE(varidclass16); // #4577
|
||||
TEST_CASE(varidclass17); // #6073
|
||||
TEST_CASE(varidclass18);
|
||||
TEST_CASE(varid_classnameshaddowsvariablename); // #3990
|
||||
|
||||
TEST_CASE(varidnamespace1);
|
||||
|
@ -2541,6 +2542,23 @@ private:
|
|||
ASSERT_EQUALS(expected, tokenize(code));
|
||||
}
|
||||
|
||||
void varidclass18() {
|
||||
const char code[] = "class A {\n"
|
||||
" int a;\n"
|
||||
" int b;\n"
|
||||
" A();\n"
|
||||
"};\n"
|
||||
"A::A() : a{0} { b = 1; }";
|
||||
const char expected[] = "\n\n##file 0\n"
|
||||
"1: class A {\n"
|
||||
"2: int a@1 ;\n"
|
||||
"3: int b@2 ;\n"
|
||||
"4: A ( ) ;\n"
|
||||
"5: } ;\n"
|
||||
"6: A :: A ( ) : a@1 { 0 } { b@2 = 1 ; }\n";
|
||||
ASSERT_EQUALS(expected, tokenize(code));
|
||||
}
|
||||
|
||||
void varid_classnameshaddowsvariablename() {
|
||||
const char code[] = "class Data;\n"
|
||||
"void strange_declarated(const Data& Data);\n"
|
||||
|
|
Loading…
Reference in New Issue