This revision was automatically updated to reflect the committed changes.
Closed by commit rL364106: [clang-tidy] misc-unused-parameters: don't 
comment out parameter name for C code (authored by mgehre, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63088?vs=203873&id=206081#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63088/new/

https://reviews.llvm.org/D63088

Files:
  clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c


Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,14 +138,19 @@
     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;
Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
@@ -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) {;}


Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,14 +138,19 @@
     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;
Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
@@ -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) {;}
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to