diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 63a3538a0..bc672056c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -54,8 +54,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti "SymbolDatabase", tok->progressValue()); // Locate next class - if (Token::Match(tok, "class|struct|union|namespace ::| %name% {|:|::|<") && - tok->strAt(-1) != "friend") { + if ((_tokenizer->isCPP() && Token::Match(tok, "class|struct|union|namespace ::| %name% {|:|::|<") && tok->strAt(-1) != "friend") + || (_tokenizer->isC() && Token::Match(tok, "struct|union| %name% {"))) { const Token *tok2 = tok->tokAt(2); if (tok->strAt(1) == "::") @@ -105,7 +105,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } // definition may be different than declaration - if (tok->str() == "class") { + if (_tokenizer->isCPP() && tok->str() == "class") { access[new_scope] = Private; new_scope->type = Scope::eClass; } else if (tok->str() == "struct") { diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 0215d5df4..58ed81bdf 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -132,6 +132,7 @@ private: TEST_CASE(garbageCode90); TEST_CASE(garbageCode91); TEST_CASE(garbageCode92); + TEST_CASE(garbageCode93); TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -511,6 +512,7 @@ private: void garbageCode40() { // #6620 checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }"); + ASSERT_THROW(checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }", "test.c"), InternalError); } void garbageCode41() { // #6685 @@ -722,6 +724,10 @@ private: ASSERT_THROW(checkCode("template < typename _Tp ( ( ) ; _Tp ) , decltype > { } { ( ) ( ) }"), InternalError); // do not crash } + void garbageCode93() { // #6800 + checkCode(" namespace A { } class A{ { }} class A : T ;", "test.c"); // do not crash + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"