diff --git a/lib/checkother.cpp b/lib/checkother.cpp index de6e295e04a..8e1f53d2863 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1869,7 +1869,7 @@ void CheckOther::checkConstPointer() continue; if (!var->isLocal() && !var->isArgument()) continue; - if (var->isArgument() && var->scope() && var->scope()->type == ScopeType::eLambda) + if (var->isArgument() && var->scope() && var->scope()->type == ScopeType::eLambda && !Token::simpleMatch(var->scope()->bodyEnd, "} (")) continue; const Token* const nameTok = var->nameToken(); if (tok == nameTok && var->isLocal() && !astIsRangeBasedForDecl(nameTok)) { diff --git a/test/testother.cpp b/test/testother.cpp index 6bc2db7e983..e83912dad03 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4697,6 +4697,12 @@ class TestOther : public TestFixture { " x();\n" "}\n"); ASSERT_EQUALS("[test.cpp:3:27]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); + + check("int f() {\n" + " int i = 0;\n" + " return [](int* p) { return *p; }(&i);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:20]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void constArray() {