diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index bf2500972fb..16e1471db07 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -113,6 +113,8 @@ void CheckBool::checkBitwiseOnBoolean() continue; const bool isBoolOp1 = astIsBool(tok->astOperand1()); const bool isBoolOp2 = astIsBool(tok->astOperand2()); + if (!tok->astOperand1()->valueType() || !tok->astOperand2()->valueType()) + continue; if (!(isBoolOp1 || isBoolOp2)) continue; if (isCompound && (!isBoolOp1 || isBoolOp2)) diff --git a/test/testbool.cpp b/test/testbool.cpp index 443fefa7097..015534ccfa0 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -954,6 +954,16 @@ class TestBool : public TestFixture { " return b;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct S { bool b{}; };\n" // #12455 + "void f(const std::unordered_map m) {\n" + " for (const auto& e : m) {\n" + " S s;\n" + " s.b |= e.second.b;\n" + " (void)s.b;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void incrementBoolean() {