diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/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. diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/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 ^^^^^^^^^^^^^^ 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 --- 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 @@ 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]