This revision was automatically updated to reflect the committed changes.
Closed by commit rL259787: [clang-tidy] More friendly warning in 
"google-runtime-references" when… (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D16882?vs=46902&id=46906#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16882

Files:
  clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
  clang-tools-extra/trunk/test/clang-tidy/google-runtime-references.cpp

Index: clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
@@ -108,9 +108,16 @@
   if (StringRef(ReferencedType.getAsString()).endswith("stream"))
     return;
 
-  diag(Parameter->getLocation(),
-       "non-const reference parameter '%0', make it const or use a pointer")
-      << Parameter->getName();
+  if (Parameter->getName().empty()) {
+    diag(Parameter->getLocation(),
+         "non-const reference parameter at index %0, "
+         "make it const or use a pointer")
+        << Parameter->getFunctionScopeIndex();
+  } else {
+    diag(Parameter->getLocation(),
+         "non-const reference parameter '%0', make it const or use a pointer")
+        << Parameter->getName();
+  }
 }
 
 } // namespace runtime
Index: clang-tools-extra/trunk/test/clang-tidy/google-runtime-references.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-runtime-references.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/google-runtime-references.cpp
@@ -40,7 +40,7 @@
 void g4(int &a, int &b, int &);
 // CHECK-MESSAGES: [[@LINE-1]]:14: warning: non-const reference parameter 'a', 
{{.*}}
 // CHECK-MESSAGES: [[@LINE-2]]:22: warning: non-const reference parameter 'b', 
{{.*}}
-// CHECK-MESSAGES: [[@LINE-3]]:30: warning: non-const reference parameter '', 
{{.*}}
+// CHECK-MESSAGES: [[@LINE-3]]:30: warning: non-const reference parameter at 
index 2, {{.*}}
 
 class B {
   B(B& a) {}
@@ -60,7 +60,7 @@
 
 // Don't warn on the first parameter of stream inserters.
 A& operator<<(A& s, int&) { return s; }
-// CHECK-MESSAGES: [[@LINE-1]]:25: warning: non-const reference parameter '', 
{{.*}}
+// CHECK-MESSAGES: [[@LINE-1]]:25: warning: non-const reference parameter at 
index 1, {{.*}}
 
 // Don't warn on either parameter of stream extractors. Both need to be
 // non-const references by convention.


Index: clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
@@ -108,9 +108,16 @@
   if (StringRef(ReferencedType.getAsString()).endswith("stream"))
     return;
 
-  diag(Parameter->getLocation(),
-       "non-const reference parameter '%0', make it const or use a pointer")
-      << Parameter->getName();
+  if (Parameter->getName().empty()) {
+    diag(Parameter->getLocation(),
+         "non-const reference parameter at index %0, "
+         "make it const or use a pointer")
+        << Parameter->getFunctionScopeIndex();
+  } else {
+    diag(Parameter->getLocation(),
+         "non-const reference parameter '%0', make it const or use a pointer")
+        << Parameter->getName();
+  }
 }
 
 } // namespace runtime
Index: clang-tools-extra/trunk/test/clang-tidy/google-runtime-references.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-runtime-references.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/google-runtime-references.cpp
@@ -40,7 +40,7 @@
 void g4(int &a, int &b, int &);
 // CHECK-MESSAGES: [[@LINE-1]]:14: warning: non-const reference parameter 'a', {{.*}}
 // CHECK-MESSAGES: [[@LINE-2]]:22: warning: non-const reference parameter 'b', {{.*}}
-// CHECK-MESSAGES: [[@LINE-3]]:30: warning: non-const reference parameter '', {{.*}}
+// CHECK-MESSAGES: [[@LINE-3]]:30: warning: non-const reference parameter at index 2, {{.*}}
 
 class B {
   B(B& a) {}
@@ -60,7 +60,7 @@
 
 // Don't warn on the first parameter of stream inserters.
 A& operator<<(A& s, int&) { return s; }
-// CHECK-MESSAGES: [[@LINE-1]]:25: warning: non-const reference parameter '', {{.*}}
+// CHECK-MESSAGES: [[@LINE-1]]:25: warning: non-const reference parameter at index 1, {{.*}}
 
 // Don't warn on either parameter of stream extractors. Both need to be
 // non-const references by convention.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to