[PATCH] D157178: [clang-tidy] Fix inline namespaces in llvm-namespace-comment
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 5 09:49:07 PDT 2023
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 @@
<clang-tidy/checks/bugprone/reserved-identifier>`, so that it does not warn
on macros starting with underscore and lowercase letter.
+- Improved :doc:`llvm-namespace-comment
+ <clang-tidy/checks/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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157178.547497.patch
Type: text/x-patch
Size: 3546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230805/0003c43e/attachment-0001.bin>
More information about the cfe-commits
mailing list