[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)
Guillaume Chatelet via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 21 06:47:44 PDT 2023
================
@@ -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
More information about the cfe-commits
mailing list