[PATCH] D116512: [clang-tidy] Limit non-Strict mode to public functions
Mehdi AMINI via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 2 18:25:08 PST 2022
mehdi_amini created this revision.
mehdi_amini added a reviewer: Eugene.Zelenko.
Herald added subscribers: carlosgalvezp, xazax.hun.
mehdi_amini requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
The rational to avoid applying the warning/fix in non-Strict more to
functions with an empty body is that there is "no place for a bug to hide".
However for private functions, the parameters can be entirely eliminated
and all the call sites improved.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116512
Files:
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
@@ -154,6 +154,10 @@
namespace {
class C {
public:
+// CHECK-FIXES: C() {}
+ C(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning
+
void f(int i);
// CHECK-FIXES: void f();
void g(int i) {;}
@@ -181,7 +185,7 @@
void useFunction(T t);
void someMoreCallSites() {
- C c;
+ C c(42);
c.f(1);
// CHECK-FIXES: c.f();
c.g(1);
Index: clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
@@ -37,6 +37,8 @@
When `false` (default value), the check will ignore trivially unused parameters,
i.e. when the corresponding function has an empty body (and in case of
- constructors - no constructor initializers). When the function body is empty,
- an unused parameter is unlikely to be unnoticed by a human reader, and
- there's basically no place for a bug to hide.
+ constructors - no constructor initializers) and the definition is public. When
+ the function body is empty, an unused parameter is unlikely to be unnoticed by
+ a human reader, and there's basically no place for a bug to hide. On the other
+ hand for non-public functions, all the call-sites are visible and the parameter
+ can be eliminated entirely.
Index: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -183,9 +183,9 @@
Param->hasAttr<UnusedAttr>())
continue;
- // In non-strict mode ignore function definitions with empty bodies
+ // In non-strict mode ignore public function definitions with empty bodies
// (constructor initializer counts for non-empty body).
- if (StrictMode ||
+ if (StrictMode || !Function->isExternallyVisible() ||
(Function->getBody()->child_begin() !=
Function->getBody()->child_end()) ||
(isa<CXXConstructorDecl>(Function) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116512.396974.patch
Type: text/x-patch
Size: 2456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220103/beb109cb/attachment.bin>
More information about the cfe-commits
mailing list