diff options
author | Haojian Wu <hokein@google.com> | 2016-02-04 14:06:49 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2016-02-04 14:06:49 +0000 |
commit | 4d67ec3f8c8861d8f8201384546efb02f9d4c8d6 (patch) | |
tree | aa3513dec0ef37a87d6f214c15f03dfb66b437a2 | |
parent | 8159cf11bc126e0d26df43f2b8fdd086a9f5bf3d (diff) | |
download | bcm5719-llvm-4d67ec3f8c8861d8f8201384546efb02f9d4c8d6.tar.gz bcm5719-llvm-4d67ec3f8c8861d8f8201384546efb02f9d4c8d6.zip |
[clang-tidy] More friendly warning in "google-runtime-references" when meeting an unnamed function parameter.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D16882
llvm-svn: 259787
-rw-r--r-- | clang-tools-extra/clang-tidy/google/NonConstReferences.cpp | 13 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/google-runtime-references.cpp | 4 |
2 files changed, 12 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp b/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp index a56d93792ed..cafc908d8a7 100644 --- a/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp +++ b/clang-tools-extra/clang-tidy/google/NonConstReferences.cpp @@ -108,9 +108,16 @@ void NonConstReferences::check(const MatchFinder::MatchResult &Result) { 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 diff --git a/clang-tools-extra/test/clang-tidy/google-runtime-references.cpp b/clang-tools-extra/test/clang-tidy/google-runtime-references.cpp index 96d82a47e22..c96f28f3009 100644 --- a/clang-tools-extra/test/clang-tidy/google-runtime-references.cpp +++ b/clang-tools-extra/test/clang-tidy/google-runtime-references.cpp @@ -40,7 +40,7 @@ void g3(ref a); 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 @@ void B::g(int &b) {} // 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. |