HerrCai0907 created this revision. HerrCai0907 added a reviewer: PiotrZSL. Herald added subscribers: carlosgalvezp, xazax.hun. Herald added a reviewer: njames93. Herald added a project: All. HerrCai0907 requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
add pre check to avoid false positive for namespace with attributes like namespace [[deprecated]] ns {} Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D147857 Files: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp @@ -21,11 +21,17 @@ } // namespace n2 namespace n5 { -inline namespace n6 { +inline namespace inline_ns { void t(); -} +} // namespace inline_ns } // namespace n5 +namespace n6 { +namespace [[deprecated]] attr_ns { +void t(); +} // namespace attr_ns +} // namespace n6 + namespace n7 { void t(); Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -305,6 +305,10 @@ <clang-tidy/checks/modernize/concat-nested-namespaces>` when using macro between namespace declarations could result incorrect fix. +- Fixed an false positive in :doc:`modernize-concat-nested-namespaces + <clang-tidy/checks/modernize/concat-nested-namespaces>` when using namespace with + attributes. + - Fixed a false positive in :doc:`performance-no-automatic-move <clang-tidy/checks/performance/no-automatic-move>` when warning would be emitted for a const local variable to which NRVO is applied. Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp @@ -31,8 +31,9 @@ return Lexer::getSourceText(TextRange, Sources, LangOpts); } -static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) { - return ND.isAnonymousNamespace() || ND.isInlineNamespace(); +static bool unsupportedNamespace(const NamespaceDecl &ND) { + return ND.isAnonymousNamespace() || ND.isInlineNamespace() || + !ND.attrs().empty(); } static bool singleNamedNamespaceChild(const NamespaceDecl &ND) { @@ -41,7 +42,7 @@ return false; const auto *ChildNamespace = dyn_cast<const NamespaceDecl>(*Decls.begin()); - return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace); + return ChildNamespace && !unsupportedNamespace(*ChildNamespace); } static bool alreadyConcatenated(std::size_t NumCandidates, @@ -166,7 +167,7 @@ if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc())) return; - if (anonymousOrInlineNamespace(ND)) + if (unsupportedNamespace(ND)) return; Namespaces.push_back(&ND);
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp @@ -21,11 +21,17 @@ } // namespace n2 namespace n5 { -inline namespace n6 { +inline namespace inline_ns { void t(); -} +} // namespace inline_ns } // namespace n5 +namespace n6 { +namespace [[deprecated]] attr_ns { +void t(); +} // namespace attr_ns +} // namespace n6 + namespace n7 { void t(); Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -305,6 +305,10 @@ <clang-tidy/checks/modernize/concat-nested-namespaces>` when using macro between namespace declarations could result incorrect fix. +- Fixed an false positive in :doc:`modernize-concat-nested-namespaces + <clang-tidy/checks/modernize/concat-nested-namespaces>` when using namespace with + attributes. + - Fixed a false positive in :doc:`performance-no-automatic-move <clang-tidy/checks/performance/no-automatic-move>` when warning would be emitted for a const local variable to which NRVO is applied. Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp @@ -31,8 +31,9 @@ return Lexer::getSourceText(TextRange, Sources, LangOpts); } -static bool anonymousOrInlineNamespace(const NamespaceDecl &ND) { - return ND.isAnonymousNamespace() || ND.isInlineNamespace(); +static bool unsupportedNamespace(const NamespaceDecl &ND) { + return ND.isAnonymousNamespace() || ND.isInlineNamespace() || + !ND.attrs().empty(); } static bool singleNamedNamespaceChild(const NamespaceDecl &ND) { @@ -41,7 +42,7 @@ return false; const auto *ChildNamespace = dyn_cast<const NamespaceDecl>(*Decls.begin()); - return ChildNamespace && !anonymousOrInlineNamespace(*ChildNamespace); + return ChildNamespace && !unsupportedNamespace(*ChildNamespace); } static bool alreadyConcatenated(std::size_t NumCandidates, @@ -166,7 +167,7 @@ if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc())) return; - if (anonymousOrInlineNamespace(ND)) + if (unsupportedNamespace(ND)) return; Namespaces.push_back(&ND);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits