================ @@ -18,32 +18,32 @@ const static StringRef RequiredNamespaceStart = "__llvm_libc"; const static StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE"; void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher( - decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl())) - .bind("child_of_translation_unit"), - this); + Finder->addMatcher(decl(isExpansionInMainFile(), + hasDeclContext(translationUnitDecl()), + unless(linkageSpecDecl())) + .bind("child_of_translation_unit"), + this); } void ImplementationInNamespaceCheck::check( const MatchFinder::MatchResult &Result) { const auto *MatchedDecl = Result.Nodes.getNodeAs<Decl>("child_of_translation_unit"); - if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation())) - return; if (const auto *NS = dyn_cast<NamespaceDecl>(MatchedDecl)) { if (!Result.SourceManager->isMacroBodyExpansion(NS->getLocation())) diag(NS->getLocation(), "the outermost namespace should be the '%0' macro") << RequiredNamespaceMacroName; - else if (!NS->getName().starts_with(RequiredNamespaceStart)) + else if (NS->isAnonymousNamespace() || ---------------- gchatelet wrote:
Yeah anonymous namespaces are not allowed. https://github.com/llvm/llvm-project/pull/66504 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits