Skip to content

Commit

Permalink
fix #13636: Syntax error for member access in noexcept (#7304)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne authored Feb 14, 2025
1 parent 5ff116d commit a57e265
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,12 +1587,13 @@ static Token * createAstAtToken(Token *tok)
do {
tok2 = tok2->next();
tok2->setCpp11init(false);
if (Token::simpleMatch(tok2, "decltype")) {
if (Token::Match(tok2, "decltype|noexcept (")) {
AST_state state(cpp);
Token *tok3 = tok2->tokAt(2);
compileExpression(tok3, state);
tok2 = tok2->linkAt(1);
}
} while (tok2 != endTok);
} while (tok2 != endTok && !precedes(endTok, tok2));
}
return endTok;
}
Expand Down
4 changes: 4 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(astrefqualifier);
TEST_CASE(astthrowdelete);
TEST_CASE(asttrailingdecltype);
TEST_CASE(astnoexcept);
TEST_CASE(astvardecl);
TEST_CASE(astnewscoped);

Expand Down Expand Up @@ -7026,6 +7027,9 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("Cc& MakeSpancdata.(csize.(,(",
testAst("template <typename C> constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {}"));
}
void astnoexcept() {
ASSERT_EQUALS("noexceptaswap.b((", testAst("void f() noexcept(noexcept(a.swap(b))) {}"));
}

//Verify that returning a newly constructed object generates the correct AST even when the class name is scoped
//Addresses https://trac.cppcheck.net/ticket/9700
Expand Down

0 comments on commit a57e265

Please sign in to comment.