Fixed #8975 (Syntax error for valid C code)
This commit is contained in:
parent
7c5015d54e
commit
5f21d9d97b
|
@ -7338,6 +7338,11 @@ bool Tokenizer::simplifyCAlternativeTokens()
|
|||
const std::map<std::string, std::string>::const_iterator cOpIt = cAlternativeTokens.find(tok->str());
|
||||
if (cOpIt != cAlternativeTokens.end()) {
|
||||
alt.push_back(tok);
|
||||
|
||||
// Is this a variable declaration..
|
||||
if (isC() && Token::Match(tok->previous(), "%type%|* %name% [;,=]"))
|
||||
return false;
|
||||
|
||||
if (!Token::Match(tok->previous(), "%name%|%num%|%char%|)|]|> %name% %name%|%num%|%char%|%op%|("))
|
||||
continue;
|
||||
if (Token::Match(tok->next(), "%assign%|%or%|%oror%|&&|*|/|%|^") && !Token::Match(tok->previous(), "%num%|%char%|) %name% *"))
|
||||
|
|
|
@ -6307,6 +6307,17 @@ private:
|
|||
tokenizeAndStringify("void f(const char *str) { while (*str=='!' or *str=='['){} }"));
|
||||
// #9920
|
||||
ASSERT_EQUALS("result = ch != s . end ( ) && * ch == ':' ;", tokenizeAndStringify("result = ch != s.end() and *ch == ':';", false, true, Settings::Native, "test.c"));
|
||||
|
||||
// #8975
|
||||
ASSERT_EQUALS("void foo ( ) {\n"
|
||||
"char * or ;\n"
|
||||
"while ( ( * or != 0 ) && ( * or != '|' ) ) { or ++ ; }\n"
|
||||
"}",
|
||||
tokenizeAndStringify(
|
||||
"void foo() {\n"
|
||||
" char *or;\n"
|
||||
" while ((*or != 0) && (*or != '|')) or++;\n"
|
||||
"}", false, true, Settings::Native, "test.c"));
|
||||
}
|
||||
|
||||
void simplifyCalculations() {
|
||||
|
|
Loading…
Reference in New Issue