Fix FN constVariableReference (#4949)

This commit is contained in:
chrchr-github 2023-04-11 14:00:40 +02:00 committed by GitHub
parent ac14fd218b
commit a0b59ff56a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -1471,6 +1471,8 @@ void CheckOther::checkConstVariable()
if (tok->isUnaryOp("&") && Token::Match(tok, "& %varid%", var->declarationId())) { if (tok->isUnaryOp("&") && Token::Match(tok, "& %varid%", var->declarationId())) {
const Token* opTok = tok->astParent(); const Token* opTok = tok->astParent();
int argn = -1; int argn = -1;
if (opTok && opTok->isUnaryOp("!"))
continue;
if (opTok && (opTok->isComparisonOp() || opTok->isAssignmentOp() || opTok->isCalculation())) { if (opTok && (opTok->isComparisonOp() || opTok->isAssignmentOp() || opTok->isCalculation())) {
if (opTok->isComparisonOp() || opTok->isCalculation()) { if (opTok->isComparisonOp() || opTok->isCalculation()) {
if (opTok->astOperand1() != tok) if (opTok->astOperand1() != tok)

View File

@ -3502,7 +3502,7 @@ private:
" int& r = i;\n" " int& r = i;\n"
" if (!&r) {}\n" " if (!&r) {}\n"
"}\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 check("class C;\n" // #11646
"void g(const C* const p);\n" "void g(const C* const p);\n"