diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 686cae492..2103644c1 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -477,7 +477,6 @@ static Token * skipDecl(Token *tok) { if (!Token::Match(tok->previous(), "( %name%")) return tok; - Token *vartok = tok; while (Token::Match(vartok, "%name%|*|&|::|<")) { if (vartok->str() == "<") { @@ -487,7 +486,7 @@ static Token * skipDecl(Token *tok) return tok; } else if (Token::Match(vartok, "%var% [:=(]")) { return vartok; - } else if (Token::simpleMatch(vartok, "decltype (")) { + } else if (Token::simpleMatch(vartok, "decltype (") && !Token::Match(tok->linkAt(1), ") [,)]")) { return vartok->linkAt(1)->next(); } vartok = vartok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d1d24a2c2..3f05e2f11 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5822,9 +5822,6 @@ private: ASSERT_EQUALS("decltypex({", testAst("decltype(x){};")); ASSERT_EQUALS("decltypexy+(yx+(", testAst("decltype(x+y)(y+x);")); ASSERT_EQUALS("decltypexy+(yx+{", testAst("decltype(x+y){y+x};")); - - // Check that decltype(x){} doesn't break AST creation for subsequent tokens. - ASSERT_EQUALS("decltypex({01:?", testAst("decltype(x){} ? 0 : 1;")); } void astbrackets() { // [] @@ -5851,6 +5848,8 @@ private: // create ast for decltype ASSERT_EQUALS("decltypex( var1=", testAst("decltype(x) var = 1;")); + ASSERT_EQUALS("a1bdecltypet((>2,(", testAst("a(1 > b(decltype(t)), 2);")); // #10271 + ASSERT_EQUALS("decltypex({01:?", testAst("decltype(x){} ? 0 : 1;")); } void astunaryop() { // unary operators