Skip to content

Commit 6d384a8

Browse files
committed
fixup! Improve isSimpleChar and move it into utils/Matchers.h
1 parent 2972062 commit 6d384a8

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ namespace clang::tidy::modernize {
2020

2121
namespace {
2222
AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
23-
AST_MATCHER(QualType, isSimpleChar) {
24-
const auto ActualType = Node.getTypePtr();
25-
return ActualType->isSpecificBuiltinType(BuiltinType::Char_S) ||
26-
ActualType->isSpecificBuiltinType(BuiltinType::Char_U);
27-
}
2823
} // namespace
2924

3025
UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
@@ -52,7 +47,8 @@ void UseStdFormatCheck::registerPPCallbacks(const SourceManager &SM,
5247
}
5348

5449
void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
55-
auto CharPointerType = hasType(pointerType(pointee(isSimpleChar())));
50+
auto CharPointerType =
51+
hasType(pointerType(pointee(matchers::isSimpleChar())));
5652
Finder->addMatcher(
5753
callExpr(
5854
argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())),

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ namespace clang::tidy::modernize {
2020

2121
namespace {
2222
AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
23-
AST_MATCHER(QualType, isSimpleChar) {
24-
const auto ActualType = Node.getTypePtr();
25-
return ActualType->isSpecificBuiltinType(BuiltinType::Char_S) ||
26-
ActualType->isSpecificBuiltinType(BuiltinType::Char_U);
27-
}
2823
} // namespace
2924

3025
UseStdPrintCheck::UseStdPrintCheck(StringRef Name, ClangTidyContext *Context)
@@ -100,7 +95,8 @@ unusedReturnValue(clang::ast_matchers::StatementMatcher MatchedCallExpr) {
10095
}
10196

10297
void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) {
103-
auto CharPointerType = hasType(pointerType(pointee(isSimpleChar())));
98+
auto CharPointerType =
99+
hasType(pointerType(pointee(matchers::isSimpleChar())));
104100
if (!PrintfLikeFunctions.empty())
105101
Finder->addMatcher(
106102
unusedReturnValue(

clang-tools-extra/clang-tidy/utils/Matchers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isPointerToConst) {
4949
return pointerType(pointee(qualType(isConstQualified())));
5050
}
5151

52+
// Returns QualType matcher for target char type only.
53+
AST_MATCHER(QualType, isSimpleChar) {
54+
const auto ActualType = Node.getTypePtr();
55+
return ActualType &&
56+
(ActualType->isSpecificBuiltinType(BuiltinType::Char_S) ||
57+
ActualType->isSpecificBuiltinType(BuiltinType::Char_U));
58+
}
59+
5260
AST_MATCHER(Expr, hasUnevaluatedContext) {
5361
if (isa<CXXNoexceptExpr>(Node) || isa<RequiresExpr>(Node))
5462
return true;

0 commit comments

Comments
 (0)