Fixed #8774 (Wrong handling of function with name 'or')

This commit is contained in:
Daniel Marjamäki 2019-12-19 19:22:39 +01:00
parent 2a2fa49098
commit c84ba10b37
2 changed files with 8 additions and 0 deletions

View File

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

View File

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