summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2019-07-17 15:22:14 +0000
committerIlya Biryukov <ibiryukov@google.com>2019-07-17 15:22:14 +0000
commitf81ee439a409973279244f093dd0264592b74a38 (patch)
tree8dd46b02baea2fe88e5c0ed1558be80fa9020fcc
parent552c2c09d354a3ad9c1c9647e0a3bb5099c31088 (diff)
downloadbcm5719-llvm-f81ee439a409973279244f093dd0264592b74a38.tar.gz
bcm5719-llvm-f81ee439a409973279244f093dd0264592b74a38.zip
[clang-tidy] Adjust location of namespace comment diagnostic
Summary: If there is no comment, place it at the closing brace of a namespace definition. Previously it was placed at the next character after the closing brace. The new position produces a better location for highlighting in clangd and does not seem to make matters worse for clang-tidy. Reviewers: alexfh, hokein Reviewed By: alexfh, hokein Subscribers: xazax.hun, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64861 llvm-svn: 366337
-rw-r--r--clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp9
-rw-r--r--clang-tools-extra/test/clang-tidy/google-readability-namespace-comments.cpp6
-rw-r--r--clang-tools-extra/test/clang-tidy/google-readability-nested-namespace-comments.cpp4
-rw-r--r--clang-tools-extra/test/clang-tidy/select-checks.cpp2
4 files changed, 14 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index 6428f8cdc98..eb3d7c505b8 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -9,6 +9,7 @@
#include "NamespaceCommentCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/StringExtras.h"
@@ -181,7 +182,13 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
? "anonymous namespace"
: ("namespace '" + NestedNamespaceName.str() + "'");
- diag(AfterRBrace, Message)
+ // Place diagnostic at an old comment, or closing brace if we did not have it.
+ SourceLocation DiagLoc =
+ OldCommentRange.getBegin() != OldCommentRange.getEnd()
+ ? OldCommentRange.getBegin()
+ : ND->getRBraceLoc();
+
+ diag(DiagLoc, Message)
<< NamespaceName
<< FixItHint::CreateReplacement(
CharSourceRange::getCharRange(OldCommentRange),
diff --git a/clang-tools-extra/test/clang-tidy/google-readability-namespace-comments.cpp b/clang-tools-extra/test/clang-tidy/google-readability-namespace-comments.cpp
index 9abb984bcbf..591c9dae5a7 100644
--- a/clang-tools-extra/test/clang-tidy/google-readability-namespace-comments.cpp
+++ b/clang-tools-extra/test/clang-tidy/google-readability-namespace-comments.cpp
@@ -7,9 +7,9 @@ namespace n2 {
void f(); // So that the namespace isn't empty.
-// CHECK-MESSAGES: :[[@LINE+4]]:2: warning: namespace 'n2' not terminated with a closing comment [google-readability-namespace-comments]
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n2' not terminated with a closing comment [google-readability-namespace-comments]
// CHECK-MESSAGES: :[[@LINE-7]]:11: note: namespace 'n2' starts here
-// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: namespace 'n1' not terminated with
+// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'n1' not terminated with
// CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1' starts here
}}
// CHECK-FIXES: } // namespace n2
@@ -25,7 +25,7 @@ void f(); // So that the namespace isn't empty.
// 5
// 6
// 7
-// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'macro_expansion' not terminated with
+// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: namespace 'macro_expansion' not terminated with
// CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'macro_expansion' starts here
}
// CHECK-FIXES: } // namespace macro_expansion
diff --git a/clang-tools-extra/test/clang-tidy/google-readability-nested-namespace-comments.cpp b/clang-tools-extra/test/clang-tidy/google-readability-nested-namespace-comments.cpp
index d7765c63820..017081d2e95 100644
--- a/clang-tools-extra/test/clang-tidy/google-readability-nested-namespace-comments.cpp
+++ b/clang-tools-extra/test/clang-tidy/google-readability-nested-namespace-comments.cpp
@@ -7,9 +7,9 @@ namespace n3 {
void f();
-// CHECK-MESSAGES: :[[@LINE+4]]:2: warning: namespace 'n3' not terminated with
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3' not terminated with
// CHECK-MESSAGES: :[[@LINE-7]]:11: note: namespace 'n3' starts here
-// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: namespace 'n1::n2' not terminated with a closing comment [google-readability-namespace-comments]
+// CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'n1::n2' not terminated with a closing comment [google-readability-namespace-comments]
// CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1::n2' starts here
}}
// CHECK-FIXES: } // namespace n3
diff --git a/clang-tools-extra/test/clang-tidy/select-checks.cpp b/clang-tools-extra/test/clang-tidy/select-checks.cpp
index 791def75b18..46bf43ca0c3 100644
--- a/clang-tools-extra/test/clang-tidy/select-checks.cpp
+++ b/clang-tools-extra/test/clang-tidy/select-checks.cpp
@@ -5,7 +5,7 @@
namespace i {
}
-// CHECK: :[[@LINE-1]]:2: warning: namespace 'i' not terminated with a closing comment [llvm-namespace-comment]
+// CHECK: :[[@LINE-1]]:1: warning: namespace 'i' not terminated with a closing comment [llvm-namespace-comment]
// Expect no warnings from the google-explicit-constructor check:
class A { A(int i); };
OpenPOWER on IntegriCloud