Skip to content

Commit ed3c870

Browse files
[ASTMatchers] Use llvm::is_detected (NFC) (#137560)
1 parent d1e85a0 commit ed3c870

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

clang/include/clang/ASTMatchers/ASTMatchersInternal.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -881,20 +881,12 @@ inline bool isDefaultedHelper(const FunctionDecl *FD) {
881881
}
882882

883883
// Metafunction to determine if type T has a member called getDecl.
884-
template <typename Ty>
885-
class has_getDecl {
886-
using yes = char[1];
887-
using no = char[2];
888-
889-
template <typename Inner>
890-
static yes& test(Inner *I, decltype(I->getDecl()) * = nullptr);
891-
892-
template <typename>
893-
static no& test(...);
884+
template <typename T>
885+
using check_has_getDecl = decltype(std::declval<T &>().getDecl());
894886

895-
public:
896-
static const bool value = sizeof(test<Ty>(nullptr)) == sizeof(yes);
897-
};
887+
template <typename T>
888+
static constexpr bool has_getDecl =
889+
llvm::is_detected<check_has_getDecl, T>::value;
898890

899891
/// Matches overloaded operators with a specific name.
900892
///

clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ TEST(HasDeclaration, HasDeclarationOfEnumType) {
226226
}
227227

228228
TEST(HasDeclaration, HasGetDeclTraitTest) {
229-
static_assert(internal::has_getDecl<TypedefType>::value,
229+
static_assert(internal::has_getDecl<TypedefType>,
230230
"Expected TypedefType to have a getDecl.");
231-
static_assert(internal::has_getDecl<RecordType>::value,
231+
static_assert(internal::has_getDecl<RecordType>,
232232
"Expected RecordType to have a getDecl.");
233-
static_assert(!internal::has_getDecl<TemplateSpecializationType>::value,
233+
static_assert(!internal::has_getDecl<TemplateSpecializationType>,
234234
"Expected TemplateSpecializationType to *not* have a getDecl.");
235235
}
236236

0 commit comments

Comments
 (0)