From 8c8952ae7c4de734189a059f71c37da6ea746dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 3 Nov 2019 12:53:30 +0100 Subject: [PATCH] Fixed #9324 (FP compareBoolExpressionWithInt - when using C++ and/or operator synonyms) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ba14c7736..92aab2d8f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7059,7 +7059,7 @@ bool Tokenizer::simplifyCAlternativeTokens() if (cOpIt != cAlternativeTokens.end()) { if (!Token::Match(tok->previous(), "%name%|%num%|%char%|)|]|> %name% %name%|%num%|%char%|%op%|(")) continue; - if (Token::Match(tok->next(), "%assign%|%or%|%oror%|&&|*|/|%|^")) + if (Token::Match(tok->next(), "%assign%|%or%|%oror%|&&|*|/|%|^") && !Token::Match(tok->previous(), "%num%|%char% %name% *")) continue; tok->str(cOpIt->second); ret = true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 29cc4f343..7ea814a3c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6151,6 +6151,9 @@ private: ASSERT_EQUALS("void f ( struct S * s ) { x = s . and + 1 ; }", tokenizeAndStringify("void f(struct S *s) { x = s->and + 1; }", false, true, Settings::Native, "test.c")); // #8745 ASSERT_EQUALS("void f ( ) { if ( x ) { or = 0 ; } }", tokenizeAndStringify("void f() { if (x) or = 0; }")); + // #9324 + ASSERT_EQUALS("void f ( const char * str ) { while ( * str == '!' || * str == '[' ) { } }", + tokenizeAndStringify("void f(const char *str) { while (*str=='!' or *str=='['){} }")); } void simplifyCalculations() {