Fixed #4503 (False positive: Incomplete statement (std::vector<int> v{1};))

This commit is contained in:
Daniel Marjamäki 2013-02-24 10:00:03 +01:00
parent 2edf95a1b9
commit df55ce14a0
2 changed files with 9 additions and 1 deletions

View File

@ -2257,6 +2257,10 @@ void CheckOther::checkIncompleteStatement()
else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), ",|: %var%") && Token::Match(tok->link(), "} [,{]")) else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), ",|: %var%") && Token::Match(tok->link(), "} [,{]"))
tok = tok->link(); tok = tok->link();
// C++11 vector initialization
else if (Token::Match(tok,"> %var% {"))
tok = tok->linkAt(2);
else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num%")) { else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num%")) {
// No warning if numeric constant is followed by a "." or "," // No warning if numeric constant is followed by a "." or ","
if (Token::Match(tok->next(), "%num% [,.]")) if (Token::Match(tok->next(), "%num% [,.]"))

View File

@ -167,7 +167,7 @@ private:
} }
void structinit() { void structinit() {
// #2462 - C++0x struct initialization // #2462 - C++11 struct initialization
check("void f() {\n" check("void f() {\n"
" ABC abc{1,2,3};\n" " ABC abc{1,2,3};\n"
"}\n"); "}\n");
@ -180,6 +180,10 @@ private:
// #4387 - C++11 initializer list // #4387 - C++11 initializer list
check("A::A() : abc{0} {}"); check("A::A() : abc{0} {}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #4503 - vector init
check("void f() { vector<int> v{1}; }");
ASSERT_EQUALS("", errout.str());
} }
void returnstruct() { void returnstruct() {