10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
20 ast_matchers::internal::Matcher<TypeLoc>, InnerMatcher) {
21 if (
Node.getIdentifier() !=
nullptr || !
Node.hasDefaultArgument() ||
22 Node.getDefaultArgument().getArgument().isNull())
25 TypeLoc DefaultArgTypeLoc =
26 Node.getDefaultArgument().getTypeSourceInfo()->getTypeLoc();
27 return InnerMatcher.matches(DefaultArgTypeLoc, Finder,
Builder);
35 hasUnnamedDefaultArgument(
37 hasNamedTypeLoc(templateSpecializationTypeLoc(
38 loc(qualType(hasDeclaration(namedDecl(
39 hasName(
"::std::enable_if"))))))
40 .bind(
"enable_if_specialization")))
47 const auto *EnableIf =
48 Result.Nodes.getNodeAs<TemplateTypeParmDecl>(
"enable_if");
49 const auto *ElaboratedLoc =
50 Result.Nodes.getNodeAs<ElaboratedTypeLoc>(
"elaborated");
51 const auto *EnableIfSpecializationLoc =
52 Result.Nodes.getNodeAs<TemplateSpecializationTypeLoc>(
53 "enable_if_specialization");
55 if (!EnableIf || !ElaboratedLoc || !EnableIfSpecializationLoc)
58 const SourceManager &SM = *Result.SourceManager;
59 SourceLocation RAngleLoc =
60 SM.getExpansionLoc(EnableIfSpecializationLoc->getRAngleLoc());
62 auto Diag =
diag(EnableIf->getBeginLoc(),
63 "incorrect std::enable_if usage detected; use "
64 "'typename std::enable_if<...>::type'");
66 Diag << FixItHint::CreateInsertion(ElaboratedLoc->getBeginLoc(),
69 Diag << FixItHint::CreateInsertion(RAngleLoc.getLocWithOffset(1),
"::type");
CodeCompletionBuilder Builder
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
const LangOptions & getLangOpts() const
Returns the language options from the context.
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.
AST_MATCHER_P(FunctionDecl, parameterCountGE, unsigned, N)
Matches functions that have at least the specified amount of parameters.