aaron.ballman created this revision. aaron.ballman added reviewers: sbenza, klimek. aaron.ballman added a subscriber: cfe-commits. Herald added a subscriber: klimek.
ASTMatchersInternal uses a custom type trait to determine the presence or absence of a getDecl member function. While the current implementation works, it requires compiler-specific hackery to work around some MSVC issues. This patch replaces the original implementation with one that requires less compiler-specific work. http://reviews.llvm.org/D17575 Files: include/clang/ASTMatchers/ASTMatchersInternal.h Index: include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- include/clang/ASTMatchers/ASTMatchersInternal.h +++ include/clang/ASTMatchers/ASTMatchersInternal.h @@ -569,32 +569,21 @@ return false; } -// Metafunction to determine if type T has a member called -// getDecl. -#if defined(_MSC_VER) && !defined(__clang__) -// For MSVC, we use a weird nonstandard __if_exists statement, as it -// is not standards-conformant enough to properly compile the standard -// code below. (At least up through MSVC 2015 require this workaround) -template <typename T> struct has_getDecl { - __if_exists(T::getDecl) { - enum { value = 1 }; - } - __if_not_exists(T::getDecl) { - enum { value = 0 }; - } +// Metafunction to determine if type T has a member called getDecl. +template <typename Ty> +class has_getDecl { + typedef char yes[1]; + typedef char no[2]; + + template <typename Inner> + static yes& test(Inner *I, decltype(I->getDecl()) * = nullptr); + + template <typename> + static no& test(...); + +public: + static const bool value = sizeof(test<Ty>(nullptr)) == sizeof(yes); }; -#else -// There is a default template inheriting from "false_type". Then, a -// partial specialization inherits from "true_type". However, this -// specialization will only exist when the call to getDecl() isn't an -// error -- it vanishes by SFINAE when the member doesn't exist. -template <typename> struct type_sink_to_void { typedef void type; }; -template <typename T, typename = void> struct has_getDecl : std::false_type {}; -template <typename T> -struct has_getDecl< - T, typename type_sink_to_void<decltype(std::declval<T>().getDecl())>::type> - : std::true_type {}; -#endif /// \brief Matches overloaded operators with a specific name. ///
Index: include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- include/clang/ASTMatchers/ASTMatchersInternal.h +++ include/clang/ASTMatchers/ASTMatchersInternal.h @@ -569,32 +569,21 @@ return false; } -// Metafunction to determine if type T has a member called -// getDecl. -#if defined(_MSC_VER) && !defined(__clang__) -// For MSVC, we use a weird nonstandard __if_exists statement, as it -// is not standards-conformant enough to properly compile the standard -// code below. (At least up through MSVC 2015 require this workaround) -template <typename T> struct has_getDecl { - __if_exists(T::getDecl) { - enum { value = 1 }; - } - __if_not_exists(T::getDecl) { - enum { value = 0 }; - } +// Metafunction to determine if type T has a member called getDecl. +template <typename Ty> +class has_getDecl { + typedef char yes[1]; + typedef char no[2]; + + template <typename Inner> + static yes& test(Inner *I, decltype(I->getDecl()) * = nullptr); + + template <typename> + static no& test(...); + +public: + static const bool value = sizeof(test<Ty>(nullptr)) == sizeof(yes); }; -#else -// There is a default template inheriting from "false_type". Then, a -// partial specialization inherits from "true_type". However, this -// specialization will only exist when the call to getDecl() isn't an -// error -- it vanishes by SFINAE when the member doesn't exist. -template <typename> struct type_sink_to_void { typedef void type; }; -template <typename T, typename = void> struct has_getDecl : std::false_type {}; -template <typename T> -struct has_getDecl< - T, typename type_sink_to_void<decltype(std::declval<T>().getDecl())>::type> - : std::true_type {}; -#endif /// \brief Matches overloaded operators with a specific name. ///
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits