Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ void CheckType::checkIntegerOverflow()
continue;

// For left shift, it's common practice to shift into the sign bit
//if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (((MathLib::bigint)1) << bits))
// continue;
if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (((MathLib::bigint)1) << bits))
continue;

integerOverflowError(tok, *value);
}
Expand Down
5 changes: 5 additions & 0 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ class TestType : public TestFixture {
" return 123456U * x;\n"
"}",settings);
ASSERT_EQUALS("", errout.str());

check("int f(int i) {\n" // #12117
" return (i == 31) ? 1 << i : 0;\n"
"}", settings);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 2.\n", errout.str());
}

void signConversion() {
Expand Down