brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · de6fa0c Raw
74 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -verify %s2// RUN: %clang_cc1 -std=c++2a -verify %s3 4struct Q { typedef int type; };5 6// "The substitution occurs in all types and expressions that are used in [...]7// template parameter declarations." In particular, we must substitute into the8// type of a parameter pack that is not a pack expansion, even if we know the9// corresponding argument pack is empty.10template<typename T, typename T::type...> void a(T);11int &a(...);12int &a_disabled = a(0);13int &a_enabled = a(Q()); // expected-error {{cannot bind to a temporary of type 'void'}}14 15template<typename T, template<typename T::type> class ...X> void b(T);16int &b(...);17int &b_disabled = b(0);18int &b_enabled = b(Q()); // expected-error {{cannot bind to a temporary of type 'void'}}19 20template<typename T, template<typename T::type...> class ...X> void c(T);21int &c(...);22int &c_disabled = c(0);23int &c_enabled = c(Q()); // expected-error {{cannot bind to a temporary of type 'void'}}24 25// The substitution proceeds in lexical order and stops when a condition that26// causes deduction to fail is encountered.27#if __cplusplus > 201702L28namespace reversed_operator_substitution_order {29  struct X { X(int); };30  struct Y { Y(int); };31  struct Cat {};32  namespace no_adl {33    Cat operator<=>(Y, X);34    bool operator<(int, Cat);35 36    template<typename T> struct indirect_sizeof {37      static_assert(sizeof(T) != 0);38      static const auto value = sizeof(T);39    };40 41    // We should substitute into the construction of the X object before the42    // construction of the Y object, so this is a SFINAE case rather than a43    // hard error. This requires substitution to proceed in lexical order44    // despite the prior rewrite to45    //    0 < (Y(...) <=> X(...))46    template<typename T> float &f(47        decltype(48          X(sizeof(T)) < Y(indirect_sizeof<T>::value)49        )50    );51    template<typename T> int &f(...);52  }53  int &r = no_adl::f<void>(true);54  float &s = no_adl::f<int>(true);55}56#endif57 58namespace GH53609 {59 60template <class, int>61struct a;62 63template <class, class...>64struct b;65 66template <class x, class... y, y... z>67struct b<x, a<y, z>...> {};68 69template <class... x> struct c: b<x>...  {};70 71c<int> d;72 73}74