10#include "clang/ASTMatchers/ASTMatchFinder.h"
19 recordType(hasDeclaration(classTemplateSpecializationDecl(
20 hasName(
"::std::allocator"),
21 hasTemplateArgument(0, refersToType(qualType(isConstQualified()))))));
23 auto hasContainerName =
24 hasAnyName(
"::std::vector",
"::std::deque",
"::std::list",
25 "::std::multiset",
"::std::set",
"::std::unordered_multiset",
26 "::std::unordered_set",
"::absl::flat_hash_set");
34 templateSpecializationTypeLoc(),
35 loc(hasUnqualifiedDesugaredType(anyOf(
36 recordType(hasDeclaration(classTemplateSpecializationDecl(
39 hasTemplateArgument(1, refersToType(allocatorConst)),
40 hasTemplateArgument(2, refersToType(allocatorConst)),
41 hasTemplateArgument(3, refersToType(allocatorConst)))))),
43 templateSpecializationType(
44 templateArgumentCountIs(1),
46 0, refersToType(qualType(isConstQualified()))),
47 hasDeclaration(namedDecl(hasContainerName)))))))
53 const auto *T = Result.Nodes.getNodeAs<TypeLoc>(
"type_loc");
57 if (isSystem(Result.Context->getSourceManager().getFileCharacteristic(
61 diag(T->getBeginLoc(),
62 "container using std::allocator<const T> is a deprecated libc++ "
63 "extension; remove const for compatibility with other standard "
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.