Skip to content

Commit ccd5884

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

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,26 @@
1111
#include "clang/ASTMatchers/ASTMatchers.h"
1212

1313
using namespace clang::ast_matchers;
14-
using namespace clang::ast_matchers::internal;
1514

1615
namespace clang::tidy::modernize {
1716

1817
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);
18+
Finder->addMatcher(
19+
traverse(TK_IgnoreUnlessSpelledInSource,
20+
functionTypeLoc(unless(hasParent(functionDecl(isExternC()))))
21+
.bind("fn")),
22+
this);
2623
Finder->addMatcher(
2724
traverse(TK_IgnoreUnlessSpelledInSource, lambdaExpr().bind("fn")), this);
2825
}
2926

3027
void RedundantVoidArgCheck::check(const MatchFinder::MatchResult &Result) {
31-
const FunctionProtoTypeLoc TL = [&] {
32-
if (const auto *TL = Result.Nodes.getNodeAs<FunctionProtoTypeLoc>("fn"))
28+
const FunctionTypeLoc TL = [&] {
29+
if (const auto *TL = Result.Nodes.getNodeAs<FunctionTypeLoc>("fn"))
3330
return *TL;
3431
return Result.Nodes.getNodeAs<LambdaExpr>("fn")
3532
->getCallOperator()
36-
->getTypeSourceInfo()
37-
->getTypeLoc()
38-
.getAs<FunctionProtoTypeLoc>();
33+
->getFunctionTypeLoc();
3934
}();
4035

4136
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)