Skip to content

Commit c7609de

Browse files
authored
fix #13634: Syntax error with decltype in trailing return type (#7301)
1 parent ad530b0 commit c7609de

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/tokenlist.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,10 +1583,15 @@ static Token * createAstAtToken(Token *tok)
15831583
}
15841584
if (Token *const endTok = skipMethodDeclEnding(tok)) {
15851585
if (Token::simpleMatch(endTok, "{")) {
1586-
const Token *tok2 = tok;
1586+
Token *tok2 = tok;
15871587
do {
15881588
tok2 = tok2->next();
15891589
tok2->setCpp11init(false);
1590+
if (Token::simpleMatch(tok2, "decltype")) {
1591+
AST_state state(cpp);
1592+
Token *tok3 = tok2->tokAt(2);
1593+
compileExpression(tok3, state);
1594+
}
15901595
} while (tok2 != endTok);
15911596
}
15921597
return endTok;

test/testtokenize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ class TestTokenizer : public TestFixture {
392392
TEST_CASE(astcase);
393393
TEST_CASE(astrefqualifier);
394394
TEST_CASE(astthrowdelete);
395+
TEST_CASE(asttrailingdecltype);
395396
TEST_CASE(astvardecl);
396397
TEST_CASE(astnewscoped);
397398

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

7024+
void asttrailingdecltype() {
7025+
ASSERT_EQUALS("Cc& csize.(", testAst("template<class C> constexpr auto s(const C &c) noexcept -> decltype(c.size()) {}"));
7026+
ASSERT_EQUALS("Cc& MakeSpancdata.(csize.(,(",
7027+
testAst("template <typename C> constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {}"));
7028+
}
7029+
70237030
//Verify that returning a newly constructed object generates the correct AST even when the class name is scoped
70247031
//Addresses https://trac.cppcheck.net/ticket/9700
70257032
void astnewscoped() {

0 commit comments

Comments
 (0)