diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 4315ccf4406..01081825280 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6571,23 +6571,6 @@ const Type* SymbolDatabase::findType(const Token *startTok, const Scope *startSc if (startTok->str() == startScope->className && startScope->isClassOrStruct() && startTok->strAt(1) != "::") return startScope->definedType; - if (startTok->isC()) { - const Scope* scope = startScope; - while (scope) { - if (startTok->str() == scope->className && scope->isClassOrStruct()) - return scope->definedType; - const Scope* typeScope = scope->findRecordInNestedList(startTok->str(), /*isC*/ true); - if (typeScope) { - if (startTok->str() == typeScope->className && typeScope->isClassOrStruct()) { - if (const Type* type = typeScope->definedType) - return type; - } - } - scope = scope->nestedIn; - } - return nullptr; - } - const Scope* start_scope = startScope; // absolute path - directly start in global scope diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c index 514f435e4c1..7b0b59aedec 100644 --- a/test/cfg/gtk.c +++ b/test/cfg/gtk.c @@ -292,7 +292,6 @@ void g_new_if_test() }; const struct a * pNew3; - // cppcheck-suppress valueFlowBailoutIncompleteVar if (pNew3 = g_new(struct a, 6)) { printf("%p", pNew3); } @@ -305,7 +304,6 @@ void g_new0_test() int b; }; // valid - // cppcheck-suppress valueFlowBailoutIncompleteVar struct a * pNew1 = g_new0(struct a, 5); printf("%p", pNew1); g_free(pNew1); @@ -324,7 +322,6 @@ void g_try_new_test() int b; }; // valid - // cppcheck-suppress valueFlowBailoutIncompleteVar struct a * pNew1 = g_try_new(struct a, 5); printf("%p", pNew1); g_free(pNew1); @@ -342,7 +339,6 @@ void g_try_new0_test() int b; }; // valid - // cppcheck-suppress valueFlowBailoutIncompleteVar struct a * pNew1 = g_try_new0(struct a, 5); printf("%p", pNew1); g_free(pNew1); @@ -360,7 +356,7 @@ void g_renew_test() struct a { int b; }; - // cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar] + // cppcheck-suppress leakReturnValNotUsed g_renew(struct a, NULL, 1); struct a * pNew = g_new(struct a, 1); @@ -375,7 +371,7 @@ void g_try_renew_test() struct a { int b; }; - // cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar] + // cppcheck-suppress leakReturnValNotUsed g_try_renew(struct a, NULL, 1); struct a * pNew = g_try_new(struct a, 1); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 7d146551d25..e6a1527f2f2 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -465,6 +465,8 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(enum18); TEST_CASE(enum19); + TEST_CASE(struct1); + TEST_CASE(sizeOfType); TEST_CASE(isImplicitlyVirtual); @@ -6859,6 +6861,42 @@ class TestSymbolDatabase : public TestFixture { } } + void struct1() { + GET_SYMBOL_DB_C("struct deer {\n" + " uint16_t a;\n" + " uint16_t b;\n" + "};\n" + "void herd ( void ) {\n" + " struct deer {\n" + " uint16_t a;\n" + " };\n" + "}"); + + ASSERT_EQUALS("", errout_str()); + ASSERT(db); + + const Token* deer = Token::findsimplematch(tokenizer.tokens(), "deer {"); + ASSERT(deer); + ASSERT(deer->type()); + ASSERT(deer->type()->classScope); + const Token* tok = deer->next(); + ASSERT(tok->scope()); + ASSERT_EQUALS_ENUM(ScopeType::eStruct, tok->scope()->type); + ASSERT_EQUALS(tok, tok->scope()->bodyStart); + ASSERT_EQUALS(tok->scope(), deer->type()->classScope); + + const Token* secondDeer = Token::findsimplematch(tok, "deer {"); + ASSERT(secondDeer); + ASSERT(secondDeer != deer); + ASSERT(secondDeer->type()); + ASSERT(secondDeer->type()->classScope); + tok = secondDeer->next(); + ASSERT(tok->scope()); + ASSERT_EQUALS_ENUM(ScopeType::eStruct, tok->scope()->type); + ASSERT_EQUALS(tok, tok->scope()->bodyStart); + ASSERT_EQUALS(tok->scope(), secondDeer->type()->classScope); + } + void sizeOfType() { // #7615 - crash in Symboldatabase::sizeOfType() GET_SYMBOL_DB("enum e;\n"