Skip to content

Commit 81f9b9b

Browse files
Fix FP with ptr to ptr const (#4050)
1 parent 80297ac commit 81f9b9b

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ void CheckOther::checkConstPointer()
15551555
continue;
15561556
if (!tok->valueType())
15571557
continue;
1558-
if (tok->valueType()->pointer == 0 || (tok->valueType()->constness & 1))
1558+
if (tok->valueType()->pointer != 1 || (tok->valueType()->constness & 1) || tok->valueType()->reference != Reference::None)
15591559
continue;
15601560
if (nonConstPointers.find(tok->variable()) != nonConstPointers.end())
15611561
continue;

test/testother.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,20 @@ class TestOther : public TestFixture {
30353035
" if (p == nullptr) {}\n"
30363036
"}\n");
30373037
ASSERT_EQUALS("", errout.str());
3038+
3039+
check("void g(int*);\n"
3040+
"void f(int* const* pp) {\n"
3041+
" int* p = pp[0];\n"
3042+
" g(p);\n"
3043+
"}\n");
3044+
ASSERT_EQUALS("", errout.str());
3045+
3046+
check("template <typename T>\n"
3047+
"struct S {\n"
3048+
" static bool f(const T& t) { return t != nullptr; }\n"
3049+
"};\n"
3050+
"S<int*> s;\n");
3051+
ASSERT_EQUALS("", errout.str());
30383052
}
30393053

30403054
void switchRedundantAssignmentTest() {
@@ -9150,7 +9164,7 @@ class TestOther : public TestFixture {
91509164
" int local_argc = 0;\n"
91519165
" local_argv[local_argc++] = argv[0];\n"
91529166
"}\n", "test.c");
9153-
ASSERT_EQUALS("[test.c:1]: (style) Parameter 'argv' can be declared with const\n", errout.str());
9167+
ASSERT_EQUALS("", errout.str());
91549168

91559169
check("void f() {\n"
91569170
" int x = 0;\n"

0 commit comments

Comments
 (0)