diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ac08f2855..6fd61e395 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2166,8 +2166,8 @@ void CheckOther::checkIncompleteStatement() else if (Token::simpleMatch(tok, "= {")) tok = tok->next()->link(); - // C++11 struct/array initialization in initializer list - else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), ",|: %var%") && Token::Match(tok->link(), "} [,{]")) + // C++11 struct/array/etc initialization in initializer list + else if (Token::Match(tok->previous(), "%var% {") && !Token::findsimplematch(tok,";",tok->link())) tok = tok->link(); // C++11 vector initialization / return { .. } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index d005a6629..a9f30d76b 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -68,6 +68,7 @@ private: TEST_CASE(returnstruct); TEST_CASE(cast); // #3009 : (struct Foo *)123.a = 1; TEST_CASE(increment); // #3251 : FP for increment + TEST_CASE(cpp11init); // #5493 : int i{1}; } void test1() { @@ -220,6 +221,13 @@ private: "}"); ASSERT_EQUALS("", errout.str()); } + + void cpp11init() { + check("void f() {\n" + " int x{1};\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestIncompleteStatement)