Skip to content

Commit a3601b2

Browse files
Fix #14409 FP constVariableReference with pointer reference (danmar#8131)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent fd1019a commit a3601b2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/checkother.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,10 +1857,13 @@ void CheckOther::checkConstPointer()
18571857
if (!var->isLocal() && !var->isArgument())
18581858
continue;
18591859
const Token* const nameTok = var->nameToken();
1860-
if (tok == nameTok) {
1860+
if (tok == nameTok && var->isLocal() && !astIsRangeBasedForDecl(nameTok)) {
1861+
if (var->isReference() && var->isPointer()) {
1862+
nonConstPointers.emplace(var);
1863+
continue;
1864+
}
18611865
// declarations of (static) pointers are (not) split up, array declarations are never split up
1862-
if (var->isLocal() && (!var->isStatic() || Token::simpleMatch(nameTok->next(), "[")) &&
1863-
!astIsRangeBasedForDecl(nameTok))
1866+
if ((!var->isStatic() || Token::simpleMatch(nameTok->next(), "[")))
18641867
continue;
18651868
}
18661869
// Skip function pointers

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,6 +4004,12 @@ class TestOther : public TestFixture {
40044004
" return static_cast<const D&>(b).i;\n"
40054005
"}\n");
40064006
ASSERT_EQUALS("[test.cpp:9:10]: (style) Parameter 'b' can be declared as reference to const [constParameterReference]\n", errout_str());
4007+
4008+
check("void f(int *p) {\n" // #14409
4009+
" int*& pp{ p };\n"
4010+
" if (*pp) {}\n"
4011+
"}\n");
4012+
ASSERT_EQUALS("", errout_str());
40074013
}
40084014

40094015
void constParameterCallback() {

0 commit comments

Comments
 (0)