Skip to content

Commit 8f33b21

Browse files
committed
test fixes, move simple matchers into ASTMatchers.h
1 parent fb68c3c commit 8f33b21

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,25 @@ using namespace clang::ast_matchers::internal;
1919
namespace clang::tidy::readability {
2020

2121
void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
22-
// NOLINTNEXTLINE(readability-identifier-naming)
23-
const VariadicDynCastAllOfMatcher<TypeLoc, TypedefTypeLoc> typedefTypeLoc;
2422
Finder->addMatcher(typedefTypeLoc().bind("typedefTypeLoc"), this);
2523

2624
if (!getLangOpts().CPlusPlus20)
2725
return;
2826

29-
// NOLINTBEGIN(readability-identifier-naming)
30-
const VariadicDynCastAllOfMatcher<Stmt, CXXNamedCastExpr> cxxNamedCastExpr;
31-
const auto inImplicitTypenameContext = anyOf(
27+
const auto InImplicitTypenameContext = anyOf(
3228
hasParent(typedefNameDecl()), hasParent(templateTypeParmDecl()),
3329
hasParent(nonTypeTemplateParmDecl()), hasParent(cxxNamedCastExpr()),
3430
hasParent(cxxNewExpr()), hasParent(friendDecl()), hasParent(fieldDecl()),
35-
hasParent(varDecl(
36-
hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())))),
31+
hasParent(
32+
varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())),
33+
unless(parmVarDecl()))),
3734
hasParent(parmVarDecl(hasParent(expr(requiresExpr())))),
3835
hasParent(parmVarDecl(hasParent(typeLoc(hasParent(
3936
namedDecl(anyOf(cxxMethodDecl(), hasParent(friendDecl()),
4037
functionDecl(has(nestedNameSpecifier()))))))))),
4138
// Match return types.
4239
hasParent(functionDecl(unless(cxxConversionDecl()))));
43-
// NOLINTEND(readability-identifier-naming)
44-
Finder->addMatcher(typeLoc(inImplicitTypenameContext).bind("typeloc"), this);
40+
Finder->addMatcher(typeLoc(InImplicitTypenameContext).bind("typeloc"), this);
4541
}
4642

4743
void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,17 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr>
27632763
extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr>
27642764
cxxConstCastExpr;
27652765

2766+
/// Matches any named cast expression.
2767+
///
2768+
/// Example: Matches all four of the casts in
2769+
/// \code
2770+
/// struct S { virtual void f(); };
2771+
/// void* ptr = dynamic_cast<void*>(reinterpret_cast<S*>(
2772+
/// const_cast<int*>(static_cast<int*>(nullptr))));
2773+
/// \endcode
2774+
extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNamedCastExpr>
2775+
cxxNamedCastExpr;
2776+
27662777
/// Matches a C-style cast expression.
27672778
///
27682779
/// Example: Matches (int) 2.2f in
@@ -6987,6 +6998,20 @@ extern const internal::VariadicDynCastAllOfMatcher<
69876998
TypeLoc, TemplateSpecializationTypeLoc>
69886999
templateSpecializationTypeLoc;
69897000

7001+
/// Matches `TypedefTypeLoc`s.
7002+
///
7003+
/// Given
7004+
/// \code
7005+
/// using t1 = int;
7006+
/// template <typename T> class C { using t2 = int; };
7007+
/// t1 var1;
7008+
/// const C<char>::t2* var2;
7009+
/// \endcode
7010+
/// typedefTypeLoc()
7011+
/// matches `t1` (in the declaration of var1) and `C<char>::t2`.
7012+
extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, TypedefTypeLoc>
7013+
typedefTypeLoc;
7014+
69907015
/// Matches template specialization `TypeLoc`s, class template specializations,
69917016
/// variable template specializations, and function template specializations
69927017
/// that have at least one `TemplateArgumentLoc` matching the given

clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,8 @@ const internal::VariadicDynCastAllOfMatcher<TypeLoc, ReferenceTypeLoc>
810810
const internal::VariadicDynCastAllOfMatcher<TypeLoc,
811811
TemplateSpecializationTypeLoc>
812812
templateSpecializationTypeLoc;
813+
const internal::VariadicDynCastAllOfMatcher<TypeLoc, TypedefTypeLoc>
814+
typedefTypeLoc;
813815

814816
const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryExprOrTypeTraitExpr>
815817
unaryExprOrTypeTraitExpr;
@@ -1009,6 +1011,8 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr>
10091011
cxxDynamicCastExpr;
10101012
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr>
10111013
cxxConstCastExpr;
1014+
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNamedCastExpr>
1015+
cxxNamedCastExpr;
10121016
const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr>
10131017
cStyleCastExpr;
10141018
const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr>

0 commit comments

Comments
 (0)