From 93297727efe65b8d41249f8a7df7d232ff28d35f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 15 Oct 2023 20:47:01 +0200 Subject: [PATCH] Fix internalASTError with decltype (refs #11378) (#5553) --- lib/tokenlist.cpp | 5 ++++- test/testtokenize.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 6cfebb4558a..2991cd7a246 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -762,6 +762,8 @@ static void compileTerm(Token *&tok, AST_state& state) tok = tok->linkAt(1); else if (Token::Match(tok, "%name% ...") || (state.op.size() == 1 && state.depth == 0 && Token::Match(tok->tokAt(-3), "!!& ) ( %name% ) ="))) tok = tok->next(); + else if (Token::simpleMatch(tok, "decltype (") && Token::simpleMatch(tok->linkAt(1), ") ::")) + tok = tok->linkAt(1); tok = tok->next(); if (Token::Match(tok, "%str%")) { while (Token::Match(tok, "%name%|%str%")) @@ -836,7 +838,8 @@ static void compileScope(Token *&tok, AST_state& state) if (Token::Match(lastOp, ":: %name%")) lastOp = lastOp->next(); if (Token::Match(lastOp, "%name%") && - (lastOp->next() == tok || (Token::Match(lastOp, "%name% <") && lastOp->linkAt(1) && tok == lastOp->linkAt(1)->next()))) + (lastOp->next() == tok || + (Token::Match(lastOp, "%name% <|(") && lastOp->linkAt(1) && tok == lastOp->linkAt(1)->next()))) compileBinOp(tok, state, compileTerm); else compileUnaryOp(tok, state, compileTerm); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d194934b2b6..7bda0678e41 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6073,7 +6073,7 @@ class TestTokenizer : public TestFixture { // C++17: if (expr1; expr2) ASSERT_EQUALS("ifx3=y;(", testAst("if (int x=3; y)")); - + ASSERT_EQUALS("xstdstring::decltypea::{=", testAst("auto x = std::string{ decltype(s)::a };")); } void astexpr2() { // limit for large expressions