diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 4aaa887d7f0..f256523d5c3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1869,6 +1869,8 @@ void CheckOther::checkConstPointer() continue; if (!var->isLocal() && !var->isArgument()) continue; + if (var->isArgument() && var->scope() && var->scope()->type == ScopeType::eLambda) + continue; const Token* const nameTok = var->nameToken(); if (tok == nameTok && var->isLocal() && !astIsRangeBasedForDecl(nameTok)) { if (var->isReference() && var->isPointer()) { diff --git a/test/testother.cpp b/test/testother.cpp index 0ccd482c353..3885705e3e4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4664,6 +4664,27 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:1:18]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:18]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("using fp_t = int (*)(int*);\n" // #14510 + "fp_t g_fp;\n" + "struct S { fp_t m_fp; };\n" + "void g(fp_t);\n" + "S f(S* s) {\n" + " g_fp = [](int* p) { return *p; };\n" + " s->m_fp = [](int* p) { return *p; };\n" + " g([](int* p) { return *p; });\n" + " auto x = [](int* p) { return *p; };\n" + " g(x);\n" + " return { [](int* p) { return *p; } };\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); + + check("void f() {\n" + " int i = 0;\n" + " auto x = [&]() { int* p = &i; if (*p) {} };\n" + " x();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:27]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); } void constArray() {