From f5b1537ed1a2a9ad5a57ef6281a2caac149e790b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 11 May 2023 14:35:23 +0200 Subject: [PATCH] Fix internalASTError with decltype() (#5047) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7ed1d9461..14e5831ad 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7549,7 +7549,7 @@ bool Tokenizer::simplifyRedundantParentheses() ret = true; } - if (Token::Match(tok->previous(), "[(,;{}] ( %name% (") && + if (Token::Match(tok->previous(), "[(,;{}] ( %name% (") && !tok->next()->isKeyword() && tok->link()->previous() == tok->linkAt(2)) { // We have "( func ( *something* ))", remove the outer // parentheses diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index db96a2303..488ba5549 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -176,6 +176,7 @@ private: TEST_CASE(removeParentheses24); // Ticket #7040 TEST_CASE(removeParentheses25); // daca@home - a=(b,c) TEST_CASE(removeParentheses26); // Ticket #8875 a[0](0) + TEST_CASE(removeParentheses27); TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -1909,6 +1910,20 @@ private: ASSERT_EQUALS(exp, tokenizeAndStringify(code)); } + void removeParentheses27() { + static char code[] = "struct S { int i; };\n" + "void g(int, int);\n" + "void f(S s, int j) {\n" + " g(j, (decltype(s.i))j * s.i);\n" + "}\n"; + static const char exp[] = "struct S { int i ; } ;\n" + "void g ( int , int ) ;\n" + "void f ( S s , int j ) {\n" + "g ( j , ( decltype ( s . i ) ) j * s . i ) ;\n" + "}"; + ASSERT_EQUALS(exp, tokenizeAndStringify(code)); + } + void tokenize_double() { const char code[] = "void f() {\n" " double a = 4.2;\n"