[clang-tools-extra] r364106 - [clang-tidy] misc-unused-parameters: don't comment out parameter name for C code
Matthias Gehre via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 21 14:30:26 PDT 2019
Author: mgehre
Date: Fri Jun 21 14:30:25 2019
New Revision: 364106
URL: http://llvm.org/viewvc/llvm-project?rev=364106&view=rev
Log:
[clang-tidy] misc-unused-parameters: don't comment out parameter name for C code
Summary: The fixit `int square(int /*num*/)` yields `error: parameter name omitted` for C code. Enable it only for C++ code.
Reviewers: klimek, ilya-biryukov, lebedev.ri, aaron.ballman
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63088
Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
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=364106&r1=364105&r2=364106&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp Fri Jun 21 14:30:25 2019
@@ -138,14 +138,19 @@ void UnusedParametersCheck::warnOnUnused
Indexer = llvm::make_unique<IndexerVisitor>(*Result.Context);
}
- // Comment out parameter name for non-local functions.
+ // Cannot remove parameter for non-local functions.
if (Function->isExternallyVisible() ||
!Result.SourceManager->isInMainFile(Function->getLocation()) ||
!Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
+
+ // It is illegal to omit parameter name here in C code, so early-out.
+ if (!Result.Context->getLangOpts().CPlusPlus)
+ return;
+
SourceRange RemovalRange(Param->getLocation());
- // 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
- // clean this up afterwards.
+ // 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 clean this up afterwards.
MyDiag << FixItHint::CreateReplacement(
RemovalRange, (Twine(" /*") + Param->getName() + "*/").str());
return;
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c?rev=364106&r1=364105&r2=364106&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c Fri Jun 21 14:30:25 2019
@@ -4,7 +4,7 @@
// =============
void a(int i) {;}
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
-// CHECK-FIXES: {{^}}void a(int /*i*/) {;}{{$}}
+// CHECK-FIXES: {{^}}void a(int i) {;}{{$}}
static void b(); // In C, forward declarations can leave out parameters.
static void b(int i) {;}
More information about the cfe-commits
mailing list