Don't warn for 'x | 0' in macro (#4172)

* Fix #11082 FN badBitmaskCheck for binary or with 0

* Add test for #10703

* Don't warn for 'x | 0' in macro

* Add test for #10876
This commit is contained in:
chrchr-github 2022-06-06 11:17:36 +02:00 committed by GitHub
parent 9c2585866c
commit 52453947c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -314,7 +314,7 @@ void CheckCondition::checkBadBitmaskCheck()
const bool isNoOp = (tok->astOperand1()->hasKnownIntValue() && tok->astOperand1()->values().front().intvalue == 0) ||
(tok->astOperand2()->hasKnownIntValue() && tok->astOperand2()->values().front().intvalue == 0);
if (isNoOp)
if (isNoOp && !tok->isExpandedMacro())
badBitmaskCheckError(tok, isNoOp);
}
}

View File

@ -893,6 +893,12 @@ private:
" if (i | j) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Operator '|' with one operand equal to zero is redundant.\n", errout.str());
check("#define EIGHTTOIS(x) (((x) << 8) | (x))\n"
"int f() {\n"
" return EIGHTTOIS(0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

View File

@ -646,6 +646,16 @@ private:
" };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("namespace N {\n" // #10876
" template <class R, class S, void(*T)(R&, float, S)>\n"
" inline void f() {}\n"
" template<class T>\n"
" void g(T& c) {\n"
" for (typename T::iterator v = c.begin(); v != c.end(); ++v) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void vardecl() {