Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
21 changes: 21 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading