From 11261a022f2720eb3e368fd88981cb6b1c82c223 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 27 Apr 2025 14:53:36 -0700 Subject: [PATCH] [ASTMatchers] Use llvm::is_detected (NFC) --- .../clang/ASTMatchers/ASTMatchersInternal.h | 18 +++++------------- .../ASTMatchers/ASTMatchersTraversalTest.cpp | 6 +++--- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index c1130ff70cf5c..8290645768aa9 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -881,20 +881,12 @@ inline bool isDefaultedHelper(const FunctionDecl *FD) { } // Metafunction to determine if type T has a member called getDecl. -template -class has_getDecl { - using yes = char[1]; - using no = char[2]; - - template - static yes& test(Inner *I, decltype(I->getDecl()) * = nullptr); - - template - static no& test(...); +template +using check_has_getDecl = decltype(std::declval().getDecl()); -public: - static const bool value = sizeof(test(nullptr)) == sizeof(yes); -}; +template +static constexpr bool has_getDecl = + llvm::is_detected::value; /// Matches overloaded operators with a specific name. /// diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index 74844167d5e5a..8759811092b6f 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -226,11 +226,11 @@ TEST(HasDeclaration, HasDeclarationOfEnumType) { } TEST(HasDeclaration, HasGetDeclTraitTest) { - static_assert(internal::has_getDecl::value, + static_assert(internal::has_getDecl, "Expected TypedefType to have a getDecl."); - static_assert(internal::has_getDecl::value, + static_assert(internal::has_getDecl, "Expected RecordType to have a getDecl."); - static_assert(!internal::has_getDecl::value, + static_assert(!internal::has_getDecl, "Expected TemplateSpecializationType to *not* have a getDecl."); }