From 81f9b9b2b723ca4e096ae638262d36cad0f4f719 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:45:11 +0200 Subject: [PATCH] Fix FP with ptr to ptr const (#4050) --- lib/checkother.cpp | 2 +- test/testother.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2613a6576..487a18e56 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1555,7 +1555,7 @@ void CheckOther::checkConstPointer() continue; if (!tok->valueType()) continue; - if (tok->valueType()->pointer == 0 || (tok->valueType()->constness & 1)) + if (tok->valueType()->pointer != 1 || (tok->valueType()->constness & 1) || tok->valueType()->reference != Reference::None) continue; if (nonConstPointers.find(tok->variable()) != nonConstPointers.end()) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 9ed594519..23c987333 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3035,6 +3035,20 @@ private: " if (p == nullptr) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void g(int*);\n" + "void f(int* const* pp) {\n" + " int* p = pp[0];\n" + " g(p);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("template \n" + "struct S {\n" + " static bool f(const T& t) { return t != nullptr; }\n" + "};\n" + "S s;\n"); + ASSERT_EQUALS("", errout.str()); } void switchRedundantAssignmentTest() { @@ -9150,7 +9164,7 @@ private: " int local_argc = 0;\n" " local_argv[local_argc++] = argv[0];\n" "}\n", "test.c"); - ASSERT_EQUALS("[test.c:1]: (style) Parameter 'argv' can be declared with const\n", errout.str()); + ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int x = 0;\n"