diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 3c72a77c8..c451f9498 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7064,6 +7064,13 @@ bool Tokenizer::simplifyCAlternativeTokens() continue; if (Token::Match(tok->next(), "%assign%|%or%|%oror%|&&|*|/|%|^") && !Token::Match(tok->previous(), "%num%|%char% %name% *")) continue; + if (executableScopeLevel == 0 && Token::Match(tok, "%name% (")) { + const Token *start = tok; + while (Token::Match(start, "%name%|*")) + start = start->previous(); + if (!start || Token::Match(start, "[;}]")) + continue; + } tok->str(cOpIt->second); ret = true; } else if (Token::Match(tok, "not|compl")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6e4489241..689eb653d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6143,6 +6143,7 @@ private: } void simplifyCAlternativeTokens() { + ASSERT_EQUALS("void or ( ) ;", tokenizeAndStringify("void or(void);", false, true, Settings::Native, "test.c")); ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }", false, true, Settings::Native, "test.c")); ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }", false, true, Settings::Native, "test.cpp")); ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }", false, true, Settings::Native, "test.c"));