Skip to content

Commit 11c3958

Browse files
Followup to #14510: constParameterPointer for immediately evaluated lambda (danmar#8252)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent ff0929a commit 11c3958

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ void CheckOther::checkConstPointer()
18691869
continue;
18701870
if (!var->isLocal() && !var->isArgument())
18711871
continue;
1872-
if (var->isArgument() && var->scope() && var->scope()->type == ScopeType::eLambda)
1872+
if (var->isArgument() && var->scope() && var->scope()->type == ScopeType::eLambda && !Token::simpleMatch(var->scope()->bodyEnd, "} ("))
18731873
continue;
18741874
const Token* const nameTok = var->nameToken();
18751875
if (tok == nameTok && var->isLocal() && !astIsRangeBasedForDecl(nameTok)) {

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,6 +4699,12 @@ class TestOther : public TestFixture {
46994699
" x();\n"
47004700
"}\n");
47014701
ASSERT_EQUALS("[test.cpp:3:27]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str());
4702+
4703+
check("int f() {\n"
4704+
" int i = 0;\n"
4705+
" return [](int* p) { return *p; }(&i);\n"
4706+
"}\n");
4707+
ASSERT_EQUALS("[test.cpp:3:20]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str());
47024708
}
47034709

47044710
void constArray() {

0 commit comments

Comments
 (0)