diff --git a/lib/checktype.cpp b/lib/checktype.cpp index d1c95d20e..f6e029290 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -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); } diff --git a/test/testtype.cpp b/test/testtype.cpp index c2e436876..d15363104 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -295,6 +295,11 @@ private: " 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() {