Skip to content

Commit 34618f9

Browse files
committed
Prefer FunctionTypeLoc over FunctionProtoTypeLoc, move matcher into ASTMatchers.h
1 parent 52be8ca commit 34618f9

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ using namespace clang::ast_matchers::internal;
1616
namespace clang::tidy::modernize {
1717

1818
void RedundantVoidArgCheck::registerMatchers(MatchFinder *Finder) {
19-
const VariadicDynCastAllOfMatcher<TypeLoc, FunctionProtoTypeLoc>
20-
functionProtoTypeLoc; // NOLINT(readability-identifier-naming)
21-
Finder->addMatcher(traverse(TK_IgnoreUnlessSpelledInSource,
22-
functionProtoTypeLoc(
23-
unless(hasParent(functionDecl(isExternC()))))
24-
.bind("fn")),
25-
this);
19+
Finder->addMatcher(
20+
traverse(TK_IgnoreUnlessSpelledInSource,
21+
functionTypeLoc(unless(hasParent(functionDecl(isExternC()))))
22+
.bind("fn")),
23+
this);
2624
Finder->addMatcher(
2725
traverse(TK_IgnoreUnlessSpelledInSource, lambdaExpr().bind("fn")), this);
2826
}
2927

3028
void RedundantVoidArgCheck::check(const MatchFinder::MatchResult &Result) {
31-
const FunctionProtoTypeLoc TL = [&] {
32-
if (const auto *TL = Result.Nodes.getNodeAs<FunctionProtoTypeLoc>("fn"))
29+
const FunctionTypeLoc TL = [&] {
30+
if (const auto *TL = Result.Nodes.getNodeAs<FunctionTypeLoc>("fn"))
3331
return *TL;
3432
return Result.Nodes.getNodeAs<LambdaExpr>("fn")
3533
->getCallOperator()
36-
->getTypeSourceInfo()
37-
->getTypeLoc()
38-
.getAs<FunctionProtoTypeLoc>();
34+
->getFunctionTypeLoc();
3935
}();
4036

4137
if (TL.getNumParams() != 0)

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7016,6 +7016,19 @@ AST_MATCHER_P(ReferenceTypeLoc, hasReferentLoc, internal::Matcher<TypeLoc>,
70167016
extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ArrayTypeLoc>
70177017
arrayTypeLoc;
70187018

7019+
/// Matches `FunctionTypeLoc`s.
7020+
///
7021+
/// Given
7022+
/// \code
7023+
/// void f(int);
7024+
/// double g(char, float) {}
7025+
/// char (*fn_ptr)();
7026+
/// \endcode
7027+
/// functionTypeLoc()
7028+
/// matches "void (int)", "double (char, float)", and "char ()".
7029+
extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, FunctionTypeLoc>
7030+
functionTypeLoc;
7031+
70197032
/// Matches template specialization `TypeLoc`s.
70207033
///
70217034
/// Given

clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,8 @@ const internal::VariadicDynCastAllOfMatcher<TypeLoc, PointerTypeLoc>
808808
const internal::VariadicDynCastAllOfMatcher<TypeLoc, ReferenceTypeLoc>
809809
referenceTypeLoc;
810810
const internal::VariadicDynCastAllOfMatcher<TypeLoc, ArrayTypeLoc> arrayTypeLoc;
811+
const internal::VariadicDynCastAllOfMatcher<TypeLoc, FunctionTypeLoc>
812+
functionTypeLoc;
811813
const internal::VariadicDynCastAllOfMatcher<TypeLoc,
812814
TemplateSpecializationTypeLoc>
813815
templateSpecializationTypeLoc;

0 commit comments

Comments
 (0)