Skip to content

Commit a0b59ff

Browse files
Fix FN constVariableReference (#4949)
1 parent ac14fd2 commit a0b59ff

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,8 @@ void CheckOther::checkConstVariable()
14711471
if (tok->isUnaryOp("&") && Token::Match(tok, "& %varid%", var->declarationId())) {
14721472
const Token* opTok = tok->astParent();
14731473
int argn = -1;
1474+
if (opTok && opTok->isUnaryOp("!"))
1475+
continue;
14741476
if (opTok && (opTok->isComparisonOp() || opTok->isAssignmentOp() || opTok->isCalculation())) {
14751477
if (opTok->isComparisonOp() || opTok->isCalculation()) {
14761478
if (opTok->astOperand1() != tok)

test/testother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3502,7 +3502,7 @@ class TestOther : public TestFixture {
35023502
" int& r = i;\n"
35033503
" if (!&r) {}\n"
35043504
"}\n");
3505-
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'r' can be declared as reference to const\n", "", errout.str()); // don't crash
3505+
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'r' can be declared as reference to const\n", errout.str()); // don't crash
35063506

35073507
check("class C;\n" // #11646
35083508
"void g(const C* const p);\n"

0 commit comments

Comments
 (0)