Skip to content

Commit 4064e44

Browse files
Fix #12916 False positive: negative shift in macro (string << i) (#6581)
1 parent 6192a35 commit 4064e44

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2999,7 +2999,7 @@ void CheckOther::checkNegativeBitwiseShift()
29992999
// don't warn if lhs is a class. this is an overloaded operator then
30003000
if (tok->isCpp()) {
30013001
const ValueType * lhsType = tok->astOperand1()->valueType();
3002-
if (!lhsType || !lhsType->isIntegral())
3002+
if (!lhsType || !lhsType->isIntegral() || lhsType->pointer)
30033003
continue;
30043004
}
30053005

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9113,6 +9113,13 @@ class TestOther : public TestFixture {
91139113
"[test.cpp:2]: (error) Shifting by a negative value is undefined behaviour\n"
91149114
"[test.cpp:3]: (portability) Shifting a negative value is technically undefined behaviour\n"
91159115
"[test.cpp:4]: (portability) Shifting a negative value is technically undefined behaviour\n", errout_str());
9116+
9117+
check("void f(int i) {\n" // #12916
9118+
" if (i < 0) {\n"
9119+
" g(\"abc\" << i);\n"
9120+
" }\n"
9121+
"}\n");
9122+
ASSERT_EQUALS("", errout_str());
91169123
}
91179124

91189125
void incompleteArrayFill() {

0 commit comments

Comments
 (0)