Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Feb 9, 2024
1 parent 3e67393 commit 73e6517
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
tok = tok->link();
}
} else if (Token::Match(tok, "%name% (")) {
if (tok->next() && Token::Match(tok->next()->link(), ") ;")) {
if (tok->next() && Token::simpleMatch(tok->next()->link(), ") ;")) {
const Token *funcStart = nullptr;
const Token *argStart = nullptr;
const Token *declEnd = nullptr;
Expand All @@ -755,10 +755,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
// save function prototype in database
if (newFunc) {
Function function(tok, scope, funcStart, argStart);
if (function.isExtern())
if (function.isExtern()) {
scope->addFunction(std::move(function));
tok = declEnd;
}
}
tok = declEnd;
continue;
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(memberFunctionOfUnknownClassMacro2);
TEST_CASE(memberFunctionOfUnknownClassMacro3);
TEST_CASE(functionLinkage);
TEST_CASE(externalFunctionsInsideAFunction); // #12420

TEST_CASE(classWithFriend);

Expand Down Expand Up @@ -2298,6 +2299,19 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(f && f->function() && !f->function()->isExtern() && f->function()->retDef->str() == "void");
}

void externalFunctionsInsideAFunction() {
GET_SYMBOL_DB("void foo( void )\n"
"{\n"
" extern void bar( void );\n"
" bar();\n"
"}\n");

ASSERT(db && errout.str().empty());

const Token *f = Token::findsimplematch(tokenizer.tokens(), "bar");
ASSERT(f && f->function() && f->function()->isExtern() && f->function()->retDef->str() == "void");
}

void classWithFriend() {
GET_SYMBOL_DB("class Foo {}; class Bar1 { friend class Foo; }; class Bar2 { friend Foo; };");
// 3 scopes: Global, 3 classes
Expand Down
2 changes: 1 addition & 1 deletion test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6957,7 +6957,7 @@ class TestUnusedVar : public TestFixture {
" int x = 0;\n"
" std::for_each(ints.begin(), ints.end(), [&x](int i){ x += i; });\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' is assigned a value that is never used.\n", "", errout.str());
}

void namespaces() { // #7557
Expand Down

0 comments on commit 73e6517

Please sign in to comment.