22 typeLoc(unless(hasAncestor(decl(isInstantiated())))).bind(
"typeLoc"),
25 if (!getLangOpts().CPlusPlus20)
28 const auto InImplicitTypenameContext =
29 anyOf(hasParent(decl(anyOf(
30 typedefNameDecl(), templateTypeParmDecl(),
31 nonTypeTemplateParmDecl(), friendDecl(), fieldDecl(),
32 parmVarDecl(hasParent(expr(requiresExpr()))),
33 parmVarDecl(hasParent(typeLoc(hasParent(decl(anyOf(
34 cxxMethodDecl(), hasParent(friendDecl()),
35 functionDecl(has(nestedNameSpecifier())),
36 cxxDeductionGuideDecl(hasDeclContext(recordDecl())))))))),
38 functionDecl(unless(cxxConversionDecl()))))),
39 hasParent(expr(anyOf(cxxNamedCastExpr(), cxxNewExpr()))));
41 typeLoc(InImplicitTypenameContext).bind(
"dependentTypeLoc"),
this);
43 varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(),
45 unless(parmVarDecl()),
46 hasTypeLoc(typeLoc().bind(
"dependentTypeLoc"))),
51 const TypeLoc TL = [&] {
52 if (
const auto *TL = Result.Nodes.getNodeAs<TypeLoc>(
"typeLoc"))
53 return TL->getType()->isDependentType() ? TypeLoc() : *TL;
55 auto TL = *Result.Nodes.getNodeAs<TypeLoc>(
"dependentTypeLoc");
56 while (
const TypeLoc Next = TL.getNextTypeLoc())
64 const SourceLocation ElaboratedKeywordLoc = [&] {
65 if (
const auto CastTL = TL.getAs<TypedefTypeLoc>())
66 return CastTL.getElaboratedKeywordLoc();
68 if (
const auto CastTL = TL.getAs<TagTypeLoc>())
69 return CastTL.getElaboratedKeywordLoc();
71 if (
const auto CastTL = TL.getAs<DeducedTemplateSpecializationTypeLoc>())
72 return CastTL.getElaboratedKeywordLoc();
74 if (
const auto CastTL = TL.getAs<TemplateSpecializationTypeLoc>())
75 return CastTL.getElaboratedKeywordLoc();
77 if (
const auto CastTL = TL.getAs<DependentNameTypeLoc>())
78 return CastTL.getElaboratedKeywordLoc();
80 return SourceLocation();
83 if (ElaboratedKeywordLoc.isInvalid())
86 if (Token ElaboratedKeyword;
87 Lexer::getRawToken(ElaboratedKeywordLoc, ElaboratedKeyword,
88 *Result.SourceManager, getLangOpts()) ||
89 ElaboratedKeyword.getRawIdentifier() !=
"typename")
92 diag(ElaboratedKeywordLoc,
"redundant 'typename'")
93 << FixItHint::CreateRemoval(ElaboratedKeywordLoc);