Skip to content

Commit

Permalink
Fix #13313 FP knownArgument with macro (danmar#7013)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 4, 2024
1 parent da410bb commit 7c764f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3902,7 +3902,7 @@ void CheckOther::checkKnownArgument()
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope *functionScope : symbolDatabase->functionScopes) {
for (const Token *tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) {
if (!tok->hasKnownIntValue())
if (!tok->hasKnownIntValue() || tok->isExpandedMacro())
continue;
if (Token::Match(tok, "++|--|%assign%"))
continue;
Expand Down
6 changes: 6 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12195,6 +12195,12 @@ class TestOther : public TestFixture {
ASSERT_EQUALS("[test.cpp:3]: (style) Argument 'i-1*i' to init list { is always 0. It does not matter what value 'i' has.\n"
"[test.cpp:4]: (style) Argument 'i-1*i' to constructor S is always 0. It does not matter what value 'i' has.\n",
errout_str());

checkP("#define MACRO(X) std::abs(X ? 0 : a)\n"
"int f(int a) {\n"
" return MACRO(true);\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void knownArgumentHiddenVariableExpression() {
Expand Down

0 comments on commit 7c764f7

Please sign in to comment.