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())))))))),
39 functionDecl(unless(cxxConversionDecl()))))),
40 hasParent(expr(anyOf(cxxNamedCastExpr(), cxxNewExpr()))));
42 typeLoc(InImplicitTypenameContext).bind(
"dependentTypeLoc"),
this);
44 varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(),
46 unless(parmVarDecl()),
47 hasTypeLoc(typeLoc().bind(
"dependentTypeLoc"))),
52 const TypeLoc TL = [&] {
53 if (
const auto *TL = Result.Nodes.getNodeAs<TypeLoc>(
"typeLoc"))
54 return TL->getType()->isInstantiationDependentType() ? TypeLoc() : *TL;
56 auto TL = *Result.Nodes.getNodeAs<TypeLoc>(
"dependentTypeLoc");
57 while (
const TypeLoc Next = TL.getNextTypeLoc())
65 const SourceLocation ElaboratedKeywordLoc = [&] {
66 if (
const auto CastTL = TL.getAs<TypedefTypeLoc>())
67 return CastTL.getElaboratedKeywordLoc();
69 if (
const auto CastTL = TL.getAs<TagTypeLoc>())
70 return CastTL.getElaboratedKeywordLoc();
72 if (
const auto CastTL = TL.getAs<DeducedTemplateSpecializationTypeLoc>())
73 return CastTL.getElaboratedKeywordLoc();
75 if (
const auto CastTL = TL.getAs<TemplateSpecializationTypeLoc>())
76 return CastTL.getElaboratedKeywordLoc();
78 if (
const auto CastTL = TL.getAs<DependentNameTypeLoc>())
79 return CastTL.getElaboratedKeywordLoc();
81 return SourceLocation();
84 if (ElaboratedKeywordLoc.isInvalid())
87 if (Token ElaboratedKeyword;
88 Lexer::getRawToken(ElaboratedKeywordLoc, ElaboratedKeyword,
89 *Result.SourceManager, getLangOpts()) ||
90 ElaboratedKeyword.getRawIdentifier() !=
"typename")
93 diag(ElaboratedKeywordLoc,
"redundant 'typename'")
94 << FixItHint::CreateRemoval(ElaboratedKeywordLoc);