diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 0ebb7d68a..53b29f5ba 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -485,6 +485,8 @@ static bool iscpp11init(const Token * const tok) return false; if (Token::Match(nameToken, "else|try|do|const|override|volatile|&|&&")) return false; + if (Token::simpleMatch(nameToken->previous(), "namespace")) + return false; // There is no initialisation for example here: 'class Fred {};' if (!Token::simpleMatch(endtok, "} ;")) return true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d1b862231..88e435c1c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -457,6 +457,7 @@ private: TEST_CASE(findGarbageCode); TEST_CASE(checkEnableIf); TEST_CASE(checkTemplates); + TEST_CASE(checkNamespaces); // #9052 TEST_CASE(noCrash1); @@ -7800,6 +7801,10 @@ private: "int main() { using T = void (*)(a>); }\n")) } + void checkNamespaces() { + ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}")) + } + void noCrash1() { ASSERT_NO_THROW(tokenizeAndStringify( "struct A {\n"