From 7c764f7ce030749f0854b41fe49285b412e8d54d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 4 Dec 2024 20:24:39 +0100 Subject: [PATCH] Fix #13313 FP knownArgument with macro (#7013) --- lib/checkother.cpp | 2 +- test/testother.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 48bc361b181..1b4cb0e1393 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; diff --git a/test/testother.cpp b/test/testother.cpp index d0a8eb896c3..90bf1b69c94 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {