Skip to content

Commit f5b1537

Browse files
Fix internalASTError with decltype() (cppcheck-opensource#5047)
1 parent e1d5d99 commit f5b1537

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7549,7 +7549,7 @@ bool Tokenizer::simplifyRedundantParentheses()
75497549
ret = true;
75507550
}
75517551

7552-
if (Token::Match(tok->previous(), "[(,;{}] ( %name% (") &&
7552+
if (Token::Match(tok->previous(), "[(,;{}] ( %name% (") && !tok->next()->isKeyword() &&
75537553
tok->link()->previous() == tok->linkAt(2)) {
75547554
// We have "( func ( *something* ))", remove the outer
75557555
// parentheses

test/testtokenize.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class TestTokenizer : public TestFixture {
176176
TEST_CASE(removeParentheses24); // Ticket #7040
177177
TEST_CASE(removeParentheses25); // daca@home - a=(b,c)
178178
TEST_CASE(removeParentheses26); // Ticket #8875 a[0](0)
179+
TEST_CASE(removeParentheses27);
179180

180181
TEST_CASE(tokenize_double);
181182
TEST_CASE(tokenize_strings);
@@ -1909,6 +1910,20 @@ class TestTokenizer : public TestFixture {
19091910
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
19101911
}
19111912

1913+
void removeParentheses27() {
1914+
static char code[] = "struct S { int i; };\n"
1915+
"void g(int, int);\n"
1916+
"void f(S s, int j) {\n"
1917+
" g(j, (decltype(s.i))j * s.i);\n"
1918+
"}\n";
1919+
static const char exp[] = "struct S { int i ; } ;\n"
1920+
"void g ( int , int ) ;\n"
1921+
"void f ( S s , int j ) {\n"
1922+
"g ( j , ( decltype ( s . i ) ) j * s . i ) ;\n"
1923+
"}";
1924+
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
1925+
}
1926+
19121927
void tokenize_double() {
19131928
const char code[] = "void f() {\n"
19141929
" double a = 4.2;\n"

0 commit comments

Comments
 (0)