[PATCH] D157178: [clang-tidy] Fix inline namespaces in llvm-namespace-comment

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG166372e0bd2d: [clang-tidy] Fix inline namespaces in 
llvm-namespace-comment (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157178

Files:
  clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
@@ -7,11 +7,39 @@
 void f();
 
 
-// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::n4' not terminated 
with
-// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::n4' starts here
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::inline n4' not 
terminated with
+// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::inline n4' starts here
 // 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::n4
+// CHECK-FIXES: }  // namespace n3::inline n4
 // CHECK-FIXES: }  // namespace n1::n2
 
+namespace n7::inline n8 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n7::inline n8
+
+namespace n9::inline n10 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n9::n10
+// CHECK-MESSAGES: :[[@LINE-1]]:2: warning: namespace 'n9::inline n10' ends 
with a comment that refers to a wrong namespace 'n9::n10' 
[google-readability-namespace-comments]
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`llvm-namespace-comment
+  ` check to provide fixes for
+  ``inline`` namespaces in the same format as :program:`clang-format`.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -23,9 +23,10 @@
 NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
-  "namespace( +([a-zA-Z0-9_:]+))?\\.? *(\\*/)?$",
-  llvm::Regex::IgnoreCase),
+  NamespaceCommentPattern(
+  "^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
+  "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$",
+  llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
 
@@ -67,8 +68,10 @@
 } else if (Nesting == 0) {
   if (T->is(tok::raw_identifier)) {
 StringRef ID = T->getRawIdentifier();
-if (ID != "namespace" && ID != "inline")
+if (ID != "namespace")
   Result.append(std::string(ID));
+if (ID == "inline")
+  Result.append(" ");
   } else if (T->is(tok::coloncolon)) {
 Result.append("::");
   } else { // Any other kind of token is unexpected here.


Index: clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
@@ -7,11 +7,39 @@
 void f();
 
 
-// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::n4' not terminated with
-// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::n4' starts here
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::inline n4' not terminated with
+// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::inline n4' starts here
 // 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::n4
+// 

[PATCH] D157178: [clang-tidy] Fix inline namespaces in llvm-namespace-comment

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157178

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157178: [clang-tidy] Fix inline namespaces in llvm-namespace-comment

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Provide fixes for inline namespaces in the same format as clang-format.

Fixes: #56804


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157178

Files:
  clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
@@ -7,11 +7,39 @@
 void f();
 
 
-// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::n4' not terminated 
with
-// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::n4' starts here
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::inline n4' not 
terminated with
+// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::inline n4' starts here
 // 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::n4
+// CHECK-FIXES: }  // namespace n3::inline n4
 // CHECK-FIXES: }  // namespace n1::n2
 
+namespace n7::inline n8 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n7::inline n8
+
+namespace n9::inline n10 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n9::n10
+// CHECK-MESSAGES: :[[@LINE-1]]:2: warning: namespace 'n9::inline n10' ends 
with a comment that refers to a wrong namespace 'n9::n10' 
[google-readability-namespace-comments]
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`llvm-namespace-comment
+  ` check to provide fixes for
+  ``inline`` namespaces in the same format as :program:`clang-format`.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -23,9 +23,10 @@
 NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
-  "namespace( +([a-zA-Z0-9_:]+))?\\.? *(\\*/)?$",
-  llvm::Regex::IgnoreCase),
+  NamespaceCommentPattern(
+  "^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
+  "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$",
+  llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
 
@@ -67,8 +68,10 @@
 } else if (Nesting == 0) {
   if (T->is(tok::raw_identifier)) {
 StringRef ID = T->getRawIdentifier();
-if (ID != "namespace" && ID != "inline")
+if (ID != "namespace")
   Result.append(std::string(ID));
+if (ID == "inline")
+  Result.append(" ");
   } else if (T->is(tok::coloncolon)) {
 Result.append("::");
   } else { // Any other kind of token is unexpected here.


Index: clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
@@ -7,11 +7,39 @@
 void f();
 
 
-// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::n4' not terminated with
-// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::n4' starts here
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::inline n4' not terminated with
+// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::inline n4' starts here
 // CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'n1::n2' not terminated with a closing comment [google-readability-namespace-comments]
 //