Skip to content

Commit

Permalink
Fix #13090 using declaration not simplified in namespace or class sco…
Browse files Browse the repository at this point in the history
…pe (danmar#6794)
  • Loading branch information
chrchr-github authored Sep 24, 2024
1 parent 437558d commit a92d852
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,12 @@ namespace {
scopeInfo = scopeInfo->addChild(ScopeInfo3::MemberFunction, scope, tok, tok->link());
added = true;
}
// inline member function
else if ((scopeInfo->type == ScopeInfo3::Record || scopeInfo->type == ScopeInfo3::Namespace) && tok1 && Token::Match(tok1->tokAt(-1), "%name% (")) {
const std::string scope = scopeInfo->name + "::" + tok1->strAt(-1);
scopeInfo = scopeInfo->addChild(ScopeInfo3::MemberFunction, scope, tok, tok->link());
added = true;
}
}

if (!added)
Expand Down
20 changes: 20 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class TestSimplifyUsing : public TestFixture {
TEST_CASE(simplifyUsing30);
TEST_CASE(simplifyUsing31);
TEST_CASE(simplifyUsing32);
TEST_CASE(simplifyUsing33);

TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971);
Expand Down Expand Up @@ -811,6 +812,25 @@ class TestSimplifyUsing : public TestFixture {
"", errout_str());
}

void simplifyUsing33() { // #13090
const char code[] = "namespace N {\n"
" using T = int;\n"
" T f() { return (T)0; }\n"
"}\n"
"struct S {\n"
" using U = int;\n"
" U g() { return (U)0; }\n"
"};\n";
const char expected[] = "namespace N { "
"int f ( ) { return ( int ) 0 ; } "
"} "
"struct S { "
"int g ( ) { return ( int ) 0 ; } "
"} ;";
ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true));
ASSERT_EQUALS("", errout_str());
}

void simplifyUsing8970() {
const char code[] = "using V = std::vector<int>;\n"
"struct A {\n"
Expand Down

0 comments on commit a92d852

Please sign in to comment.