Skip to content

Commit bc9349a

Browse files
authored
Fix #14919: FP constVariableReference (initialization with parentheses) (#8731)
1 parent 8e5682d commit bc9349a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3001,7 +3001,7 @@ bool isVariableChanged(const Variable * var, const Settings &settings, int depth
30013001
const Token * start = var->declEndToken();
30023002
if (!start)
30033003
return false;
3004-
if (Token::Match(start, "; %varid% =", var->declarationId()))
3004+
if (Token::Match(start, "; %varid% =", var->declarationId()) && !Token::simpleMatch(start->previous(), ")"))
30053005
start = start->tokAt(2);
30063006
if (Token::simpleMatch(start, "=")) {
30073007
const Token* next = nextAfterAstRightmostLeafGeneric(start);

test/testother.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,6 +4146,14 @@ class TestOther : public TestFixture {
41464146
" *o = 1;\n"
41474147
"}\n");
41484148
ASSERT_EQUALS("", errout_str());
4149+
4150+
check("int f() {\n"
4151+
" int x = 0;\n"
4152+
" int& r(x);\n"
4153+
" r = x;\n"
4154+
" return r;\n"
4155+
"}\n");
4156+
ASSERT_EQUALS("", errout_str());
41494157
}
41504158

41514159
void constParameterCallback() {

0 commit comments

Comments
 (0)