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:
parent
9c2585866c
commit
52453947c8
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue