Fix FP with ptr to ptr const (#4050)

This commit is contained in:
chrchr-github 2022-04-25 21:45:11 +02:00 committed by GitHub
parent 80297acad0
commit 81f9b9b2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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;

View File

@ -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 <typename T>\n"
"struct S {\n"
" static bool f(const T& t) { return t != nullptr; }\n"
"};\n"
"S<int*> 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"