diff --git a/lib/checktype.cpp b/lib/checktype.cpp index f80eea9ec1a..a9eda1b8a82 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -72,6 +72,8 @@ void CheckType::checkTooBigBitwiseShift() if (tok->isCpp() && Token::Match(tok, "[;{}] %name% (") && Token::simpleMatch(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function()) tok = tok->linkAt(2); + tok = skipUnreachableBranch(tok); + if (!tok->astOperand1() || !tok->astOperand2()) continue; diff --git a/test/testtype.cpp b/test/testtype.cpp index ac602dc4bde..bc422af4ab9 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -44,6 +44,7 @@ class TestType : public TestFixture { TEST_CASE(longCastReturn); TEST_CASE(checkFloatToIntegerOverflow); TEST_CASE(integerOverflow); // #11794 + TEST_CASE(shiftTooManyBits); // #11496 } #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) @@ -588,6 +589,18 @@ class TestType : public TestFixture { "}", s, "test.cpp"); ASSERT_EQUALS("[test.cpp:4]: (error) Signed integer overflow for expression 'i<<2'.\n", errout_str()); } + + void shiftTooManyBits() { // #11496 + check("template struct B {\n" + " unsigned long long f(unsigned int n) const {\n" + " if (width == 1)\n" + " return 1ULL << width;\n" + " return 0;\n" + " }\n" + "};\n" + "static B<64> b;\n", settingsDefault); + ASSERT_EQUALS("", errout_str()); + } }; REGISTER_TEST(TestType)