Skip to content

Commit 7dbb1fa

Browse files
authored
Fix #13735 AST:function name in parantheses (#8183)
https://trac.cppcheck.net/ticket/13735 If the start paranthese is preceeded by a keyword like "return" the parantheses removal is aborted. Added no abort removal of parantheses in simplifyParenthesizedLibraryFunctionsif the preceeding %name% is a keyword, like "return (modf) ...
1 parent 380cf9a commit 7dbb1fa

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3790,7 +3790,7 @@ void Tokenizer::simplifyParenthesizedLibraryFunctions()
37903790
if (!Token::simpleMatch(tok, ") ("))
37913791
continue;
37923792
Token *rpar = tok, *lpar = tok->link();
3793-
if (!lpar || Token::Match(lpar->previous(), "%name%"))
3793+
if (!lpar || (Token::Match(lpar->previous(), "%name%") && !lpar->previous()->isKeyword()))
37943794
continue;
37953795
const Token *ftok = rpar->previous();
37963796
if (mSettings.library.isNotLibraryFunction(ftok))

test/testtokenize.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class TestTokenizer : public TestFixture {
184184
TEST_CASE(removeParentheses26); // Ticket #8875 a[0](0)
185185
TEST_CASE(removeParentheses27);
186186
TEST_CASE(removeParentheses28); // #12164 - don't remove parentheses in '(expr1) ? (expr2) : (expr3);'
187+
TEST_CASE(removeParantheses29); // #13735
187188

188189
TEST_CASE(tokenize_double);
189190
TEST_CASE(tokenize_strings);
@@ -2179,6 +2180,18 @@ class TestTokenizer : public TestFixture {
21792180
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
21802181
}
21812182

2183+
void removeParantheses29() { // Ticket #13735
2184+
static char code[] = "double foo(void)\n"
2185+
"{\n"
2186+
"return (modf)(12.3, NULL);\n"
2187+
"}";
2188+
static const char exp[] = "double foo ( )\n"
2189+
"{\n"
2190+
"return modf ( 12.3 , NULL ) ;\n"
2191+
"}";
2192+
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
2193+
}
2194+
21822195
void tokenize_double() {
21832196
const char code[] = "void f() {\n"
21842197
" double a = 4.2;\n"

0 commit comments

Comments
 (0)