Skip to content

Commit

Permalink
Fix #11981 internalAstError with using declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 13, 2023
1 parent 523c41a commit 4487578
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3236,9 +3236,18 @@ bool Tokenizer::simplifyUsing()
}
}

// just replace simple type aliases
TokenList::copyTokens(tok1, start, usingEnd->previous());
tok1->deleteThis();
// Is this a "T()" expression where T is a pointer type?
if (Token::Match(tok1, "%name% ( )") && !pointers.empty()) {
auto tok2 = tok1->linkAt(1);
tok1->deleteThis();
TokenList::copyTokens(tok1, start, usingEnd->previous());
tok2->insertToken("0");
after = tok2->next();
}
else { // just replace simple type aliases
TokenList::copyTokens(tok1, start, usingEnd->previous());
tok1->deleteThis();
}
substitute = true;
}
} else {
Expand Down
9 changes: 9 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class TestSimplifyUsing : public TestFixture {
TEST_CASE(simplifyUsing26); // #11090
TEST_CASE(simplifyUsing27);
TEST_CASE(simplifyUsing28);
TEST_CASE(simplifyUsing29);

TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971);
Expand Down Expand Up @@ -684,6 +685,14 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void simplifyUsing29() { // #11981
const char code[] = "using T = int*;\n"
"void f(T = T()) {}\n";
const char expected[] = "void f ( int * = ( int * ) 0 ) { }";
ASSERT_EQUALS(expected, tok(code, cppcheck::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 4487578

Please sign in to comment.