Author: Piotr Zegar Date: 2023-08-05T16:47:48Z New Revision: 166372e0bd2db5de459fc9d4be7ea9873ce983f4
URL: https://github.com/llvm/llvm-project/commit/166372e0bd2db5de459fc9d4be7ea9873ce983f4 DIFF: https://github.com/llvm/llvm-project/commit/166372e0bd2db5de459fc9d4be7ea9873ce983f4.diff LOG: [clang-tidy] Fix inline namespaces in llvm-namespace-comment Provide fixes for inline namespaces in the same format as clang-format. Fixes: #56804 Reviewed By: carlosgalvezp Differential Revision: https://reviews.llvm.org/D157178 Added: Modified: 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 Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index ad2d396311ed21..21e3bd08255d98 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -23,9 +23,10 @@ namespace clang::tidy::readability { 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 @@ getNamespaceNameAsWritten(SourceLocation &Loc, const SourceManager &Sources, } 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. diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index ba3a5d4a127653..a88df4d9f8909b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -163,6 +163,10 @@ Changes in existing checks <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 ^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp index e4626020ebaab9..f8c3ce5a5ee3c1 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp @@ -7,11 +7,39 @@ namespace /*comment1*/n3/*comment2*/::/*comment3*/inline/*comment4*/n4/*comment5 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] _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits