Fix internalASTError with decltype() (#5047)

This commit is contained in:
chrchr-github 2023-05-11 14:35:23 +02:00 committed by GitHub
parent e1d5d9988d
commit f5b1537ed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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"