diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f99751eab..d9278a290 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1471,6 +1471,8 @@ void CheckOther::checkConstVariable() if (tok->isUnaryOp("&") && Token::Match(tok, "& %varid%", var->declarationId())) { const Token* opTok = tok->astParent(); int argn = -1; + if (opTok && opTok->isUnaryOp("!")) + continue; if (opTok && (opTok->isComparisonOp() || opTok->isAssignmentOp() || opTok->isCalculation())) { if (opTok->isComparisonOp() || opTok->isCalculation()) { if (opTok->astOperand1() != tok) diff --git a/test/testother.cpp b/test/testother.cpp index c5c6ad650..a374d440f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3502,7 +3502,7 @@ private: " int& r = i;\n" " if (!&r) {}\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'r' can be declared as reference to const\n", "", errout.str()); // don't crash + ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'r' can be declared as reference to const\n", errout.str()); // don't crash check("class C;\n" // #11646 "void g(const C* const p);\n"