From: Nick Kledzik Date: Mon, 17 Dec 2012 19:02:05 +0000 (+0000) Subject: Use different trait techniques to be compatible with g++ X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fbc8a73e0c9f4e9da49faa4782c9bfb0acb50a24;p=oota-llvm.git Use different trait techniques to be compatible with g++ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170355 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/YAMLTraits.h b/include/llvm/Support/YAMLTraits.h index 80580620ea8..4487eae2482 100644 --- a/include/llvm/Support/YAMLTraits.h +++ b/include/llvm/Support/YAMLTraits.h @@ -227,10 +227,9 @@ public: }; -// Test if SequenceTraits is defined on type T -// and SequenceTraits::flow is *not* defined. +// Test if SequenceTraits is defined on type T. template -struct has_SequenceTraits +struct has_SequenceMethodTraits { typedef size_t (*Signature_size)(class IO&, T&); @@ -240,43 +239,59 @@ struct has_SequenceTraits template static double test(...); - template static - char flowtest( char[sizeof(&U::flow)] ) ; +public: + static bool const value = (sizeof(test >(0)) == 1); +}; - template - static double flowtest(...); +// has_FlowTraits will cause an error with some compilers because +// it subclasses int. Using this wrapper only instantiates the +// real has_FlowTraits only if the template type is a class. +template ::value> +class has_FlowTraits +{ public: - static bool const value = (sizeof(test >(0)) == 1) - && (sizeof(flowtest(0)) != 1); + static const bool value = false; }; - -// Test if SequenceTraits is defined on type T -// and SequenceTraits::flow is defined. +// Some older gcc compilers don't support straight forward tests +// for members, so test for ambiguity cause by the base and derived +// classes both defining the member. template -struct has_FlowSequenceTraits +struct has_FlowTraits { - typedef size_t (*Signature_size)(class IO&, T&); + struct Fallback { bool flow; }; + struct Derived : T, Fallback { }; - template - static char test(SameType*); - - template - static double test(...); + template + static char (&f(SameType*))[1]; - template static - char flowtest( char[sizeof(&U::flow)] ) ; - - template - static double flowtest(...); + template + static char (&f(...))[2]; public: - static bool const value = (sizeof(test >(0)) == 1) - && (sizeof(flowtest(0)) == 1); + static bool const value = sizeof(f(0)) == 2; }; + +// Test if SequenceTraits is defined on type T +// and SequenceTraits::flow is *not* defined. +template +struct has_SequenceTraits : public llvm::integral_constant::value + && !has_FlowTraits::value > { }; + + +// Test if SequenceTraits is defined on type T +// and SequenceTraits::flow is defined. +template +struct has_FlowSequenceTraits : public llvm::integral_constant::value + && has_FlowTraits::value > { }; + + + // Test if DocumentListTraits is defined on type T template struct has_DocumentListTraits