Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7805,7 +7805,7 @@ bool Tokenizer::simplifyCAlternativeTokens()
alt.push_back(tok);

// Is this a variable declaration..
if (isC() && Token::Match(tok->previous(), "%type%|* %name% [;,=]"))
if (isC() && Token::Match(tok->previous(), "%type%|* %name% [;,=)]"))
return false;

if (!Token::Match(tok->previous(), "%name%|%num%|%char%|%str%|)|]|> %name% %name%|%num%|%char%|%op%|%str%|("))
Expand All @@ -7823,6 +7823,10 @@ bool Tokenizer::simplifyCAlternativeTokens()
} else if (Token::Match(tok, "not|compl")) {
alt.push_back(tok);

// Is this a variable/parameter declaration
if (isC() && Token::Match(tok->previous(), "%type%|* %name% [;,=)]"))
return false;

if ((Token::Match(tok->previous(), "%assign%") || Token::Match(tok->next(), "%num%")) && !Token::Match(tok->next(), ".|->")) {
replaceAll = true;
continue;
Expand Down
14 changes: 14 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5449,6 +5449,20 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS(exp, tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false)));
}

{ // not used as parameter name in C
const char code[] = "static void foo(int not, int test) {"
" test = not;"
"}";
const char exp[] = "static void foo ( int not , int test ) { test = not ; }";
ASSERT_EQUALS(exp, tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false)));
}

{ // binary alt token as last parameter in C
const char code[] = "void f(int or) { if (or) {} }";
const char exp[] = "void f ( int or ) { if ( or ) { } }";
ASSERT_EQUALS(exp, tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false)));
}

//ASSERT_EQUALS("", filter_valueflow(errout_str()));
ignore_errout();
}
Expand Down
Loading