[clang-tools-extra] r243414 - misc-unused-parameters: Only remove parameters in the main source file.
Daniel Jasper
djasper at google.com
Tue Jul 28 06:19:12 PDT 2015
Author: djasper
Date: Tue Jul 28 08:19:12 2015
New Revision: 243414
URL: http://llvm.org/viewvc/llvm-project?rev=243414&view=rev
Log:
misc-unused-parameters: Only remove parameters in the main source file.
In headers, they might always be pulled in to different TUs, even if
they are declared static or nested in an unnamed namespace.
Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp?rev=243414&r1=243413&r2=243414&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp Tue Jul 28 08:19:12 2015
@@ -70,7 +70,9 @@ void UnusedParametersCheck::warnOnUnused
};
// Comment out parameter name for non-local functions.
- if (Function->isExternallyVisible() || UsedByRef()) {
+ if (Function->isExternallyVisible() ||
+ !Result.SourceManager->isInMainFile(Function->getLocation()) ||
+ UsedByRef()) {
SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
// Note: We always add a space before the '/*' to not accidentally create a
// '*/*' for pointer types, which doesn't start a comment. clang-format will
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp?rev=243414&r1=243413&r2=243414&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp Tue Jul 28 08:19:12 2015
@@ -1,6 +1,12 @@
-// RUN: $(dirname %s)/check_clang_tidy.sh %s misc-unused-parameters %t
+// RUN: echo "static void staticFunctionHeader(int i) {}" > %T/header.h
+// RUN: echo "static void staticFunctionHeader(int /*i*/) {}" > %T/header-fixed.h
+// RUN: $(dirname %s)/check_clang_tidy.sh %s misc-unused-parameters %t -header-filter='.*' --
+// RUN: diff %T/header.h %T/header-fixed.h
// REQUIRES: shell
+#include "header.h"
+// CHECK-MESSAGES: header.h:1:38: warning
+
// Basic removal
// =============
void a(int i) {}
More information about the cfe-commits
mailing list