]> granicus.if.org Git - clang/commitdiff
Revert "[TrailingObjects] Use a different technique to determine if a getDecl"
authorJames Y Knight <jyknight@google.com>
Tue, 29 Dec 2015 04:46:43 +0000 (04:46 +0000)
committerJames Y Knight <jyknight@google.com>
Tue, 29 Dec 2015 04:46:43 +0000 (04:46 +0000)
This reverts commit r256534.

Failed to build on MSVC with error:
clang/ASTMatchers/ASTMatchersInternal.h(572): error C2228: left of '.getDecl' must have class/struct/union
        type is 'add_rvalue_reference<_Ty>::type'

(http://lab.llvm.org:8011/builders/lldb-x86-win7-msvc/builds/13873/steps/build/logs/stdio)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256535 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchersInternal.h

index 816dc435a4f8d8f5a34c4d627c5767a7206aa01a..22068b48e7992a480bd7656aa16ff21c74ed736c 100644 (file)
@@ -558,19 +558,22 @@ bool matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start,
   return false;
 }
 
-/// Metafunction to determine if type T has a member called
-/// getDecl.
-///
-/// 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 {};
+/// \brief Metafunction to determine if type T has a member called getDecl.
+template <typename T> struct has_getDecl {
+  struct Default { int getDecl; };
+  struct Derived : T, Default { };
+
+  template<typename C, C> struct CheckT;
+
+  // If T::getDecl exists, an ambiguity arises and CheckT will
+  // not be instantiable. This makes f(...) the only available
+  // overload.
+  template<typename C>
+  static char (&f(CheckT<int Default::*, &C::getDecl>*))[1];
+  template<typename C> static char (&f(...))[2];
+
+  static bool const value = sizeof(f<Derived>(nullptr)) == 2;
+};
 
 /// \brief Matches overloaded operators with a specific name.
 ///