Skip to content

Commit

Permalink
fix #13634: Syntax error with decltype in trailing return type (#7301)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne authored Feb 13, 2025
1 parent ad530b0 commit c7609de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,10 +1583,15 @@ static Token * createAstAtToken(Token *tok)
}
if (Token *const endTok = skipMethodDeclEnding(tok)) {
if (Token::simpleMatch(endTok, "{")) {
const Token *tok2 = tok;
Token *tok2 = tok;
do {
tok2 = tok2->next();
tok2->setCpp11init(false);
if (Token::simpleMatch(tok2, "decltype")) {
AST_state state(cpp);
Token *tok3 = tok2->tokAt(2);
compileExpression(tok3, state);
}
} while (tok2 != endTok);
}
return endTok;
Expand Down
7 changes: 7 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(astcase);
TEST_CASE(astrefqualifier);
TEST_CASE(astthrowdelete);
TEST_CASE(asttrailingdecltype);
TEST_CASE(astvardecl);
TEST_CASE(astnewscoped);

Expand Down Expand Up @@ -7020,6 +7021,12 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("a(", testAst("class a { virtual ~a() throw() = delete; };"));
}

void asttrailingdecltype() {
ASSERT_EQUALS("Cc& csize.(", testAst("template<class C> constexpr auto s(const C &c) noexcept -> decltype(c.size()) {}"));
ASSERT_EQUALS("Cc& MakeSpancdata.(csize.(,(",
testAst("template <typename C> constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {}"));
}

//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
void astnewscoped() {
Expand Down

0 comments on commit c7609de

Please sign in to comment.