From 9dd7dbfc7102558b08f3c2b51d56485e85f7b56d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Feb 2026 16:36:18 +0100 Subject: [PATCH 1/9] Update checkother.cpp --- lib/checkother.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 4aaa887d7f0..791de31021d 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->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()) { From a4562799ba993d34566bef2c97a8a49d5be39761 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Feb 2026 16:44:50 +0100 Subject: [PATCH 2/9] Update testother.cpp --- test/testother.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 0ccd482c353..c71ab7922ca 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4664,6 +4664,20 @@ 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; + "struct S { fp_t m_fp; }; + "void g(fp_t); + "S f(S* s) { + " g_fp = [](int* p) { return *p; }; + " s->m_fp = [](int* p) { return *p; }; + " g([](int* p) { return *p; }); + " auto x = [](int* p) { return *p; }; + " g(x); + " return { [](int* p) { return *p; } }; + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constArray() { From 12578b27e1584cf11592259b740ad058ce7902ed Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Feb 2026 16:51:32 +0100 Subject: [PATCH 3/9] Update checkother.cpp --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 791de31021d..f256523d5c3 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->scope() && var->scope()->type == ScopeType::eLambda) + if (var->isArgument() && var->scope() && var->scope()->type == ScopeType::eLambda) continue; const Token* const nameTok = var->nameToken(); if (tok == nameTok && var->isLocal() && !astIsRangeBasedForDecl(nameTok)) { From 8e837c40d638d1d831f4c2af60fbedc2cc3bedf5 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Feb 2026 16:55:36 +0100 Subject: [PATCH 4/9] Update testother.cpp --- test/testother.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index c71ab7922ca..8c3038f62b0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4678,6 +4678,13 @@ class TestOther : public TestFixture { " return { [](int* p) { return *p; } }; "}\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:24]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]", errout_str()); } void constArray() { From 9aaf750495e1aeb5ebe4d4cb0265c2bcce58132a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:09:57 +0100 Subject: [PATCH 5/9] Update testother.cpp --- test/testother.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 8c3038f62b0..1ffb46c38db 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4666,16 +4666,16 @@ class TestOther : public TestFixture { errout_str()); check("using fp_t = int (*)(int*);\n" // #14510 - "fp_t g_fp; - "struct S { fp_t m_fp; }; - "void g(fp_t); - "S f(S* s) { - " g_fp = [](int* p) { return *p; }; - " s->m_fp = [](int* p) { return *p; }; - " g([](int* p) { return *p; }); - " auto x = [](int* p) { return *p; }; - " g(x); - " return { [](int* p) { return *p; } }; + "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()); From 58c5d389f4b7354bb29da5d81692504d7fc90876 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:18:29 +0100 Subject: [PATCH 6/9] Update testother.cpp --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index 1ffb46c38db..3f55cec7d98 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4684,7 +4684,7 @@ class TestOther : public TestFixture { " auto x = [&]() { int* p = &i; if (*p) {} };\n" " x();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3:24]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]", errout_str()); + ASSERT_EQUALS("[test.cpp:3:27]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); } void constArray() { From ce9e53655b9e2a39b90cc68737841c42b7f6336e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 18 Feb 2026 19:42:59 +0100 Subject: [PATCH 7/9] Format --- test/testother.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 3f55cec7d98..3885705e3e4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4670,21 +4670,21 @@ class TestOther : public TestFixture { "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_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" + " 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()); + 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() { From 8bf72f5d04fa447f924914c7aad7bf9dc1065a6c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:10:15 +0100 Subject: [PATCH 8/9] Update checkother.cpp --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f256523d5c3..84da15646fc 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)) { From 3ab6ade1184fe17fe49236b9f0d8af1b2b31d143 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:11:05 +0100 Subject: [PATCH 9/9] Update testother.cpp --- test/testother.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 3885705e3e4..e6121d2c4c0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4685,6 +4685,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() {