From f2420509c9b41a96e002206182a88dbff13b1ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 13 Feb 2022 08:40:45 +0100 Subject: [PATCH] Revert "constPointer: Fix false positives when pointer is not read" This reverts commit 6427b4888bc36dd5177b3d88c7c07276444333c5. If variable/parameter is unused it is better to warn about that. --- lib/checkother.cpp | 4 ++-- test/testother.cpp | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 789c7897b..b41d09b6f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1540,6 +1540,8 @@ void CheckOther::checkConstPointer() continue; if (!tok->variable()->isLocal() && !tok->variable()->isArgument()) continue; + if (tok == tok->variable()->nameToken()) + continue; if (!tok->valueType()) continue; if (tok->valueType()->pointer == 0 || tok->valueType()->constness > 0) @@ -1547,8 +1549,6 @@ void CheckOther::checkConstPointer() if (nonConstPointers.find(tok->variable()) != nonConstPointers.end()) continue; pointers.insert(tok->variable()); - if (tok == tok->variable()->nameToken()) - continue; const Token *parent = tok->astParent(); bool deref = false; if (parent && parent->isUnaryOp("*")) diff --git a/test/testother.cpp b/test/testother.cpp index 5ac7c98fb..027d89599 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -677,10 +677,10 @@ private: // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition check("void f() {\n" - " double* p1= new double[1];\n" - " double* p2= new double[1];\n" - " double* p3= new double[1];\n" - " const double* pp[3] = {p1,p2,p3};\n" + "double* p1= new double[1];\n" + "double* p2= new double[1];\n" + "double* p3= new double[1];\n" + "double* pp[3] = {p1,p2,p3};\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -2778,9 +2778,6 @@ private: } void constPointer() { - check("void foo(void* data) {}"); - ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'data' can be declared with const\n", errout.str()); - check("void foo(int *p) { return *p; }"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p' can be declared with const\n", errout.str()); @@ -4754,7 +4751,7 @@ private: ASSERT_EQUALS("", errout.str()); check("void f() {\n" - " const std::array,3> array;\n" + " std::array,3> array;\n" "}\n"); ASSERT_EQUALS("", errout.str()); }