[PATCH] D64861: [clang-tidy] Adjust location of namespace comment diagnostic

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 08:21:55 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL366337: [clang-tidy] Adjust location of namespace comment diagnostic (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64861?vs=210300&id=210336#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64861

Files:
  clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp
  clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
  clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp


Index: clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ clang-tools-extra/trunk/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 @@
           ? "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),
Index: clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments.cpp
@@ -7,9 +7,9 @@
 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 @@
 // 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
Index: clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp
+++ clang-tools-extra/trunk/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); };
Index: clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
@@ -7,9 +7,9 @@
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64861.210336.patch
Type: text/x-patch
Size: 4088 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190717/b7b45e67/attachment.bin>


More information about the llvm-commits mailing list