brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · 34c5c5d Raw
129 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s2// RUN: %clang_cc1 -std=c++2c -x c++ -verify %s3 4template<typename T> concept True = true;5template<typename T> concept Foo = True<T*>; // #Foo6template<typename T> concept Bar = Foo<T&>;  // #Bar7template<typename T> requires Bar<T> struct S { }; // #S8template<typename T> requires Bar<T> && true struct S<T> { }; // #SpecS9// expected-error@-1 {{class template partial specialization is not more specialized than the primary template}}10// expected-error@#Foo 2{{'type name' declared as a pointer to a reference of type 'T &'}}11// expected-note@#SpecS {{while substituting into concept arguments here}}12// expected-note@#S {{while substituting into concept arguments here}}13// expected-note@#Bar 2{{while substituting into concept arguments here}}14// expected-note@#S {{template is declared here}}15 16 17 18template<typename T> concept True2 = sizeof(T) >= 0;19template<typename T> concept Foo2 = True2<T*>; // #Foo220 21template<typename T> concept Bar2 = Foo2<T&>; // #Bar222// expected-note@-1 3{{while substituting into concept arguments here; substitution failures not allowed in concept arguments}}23template<typename T> requires Bar2<T> struct S2 { }; // #SpecS2_124// expected-note@-1{{template is declared here}}25template<typename T> requires Bar2<T> && true struct S2<T> { }; // #SpecS2_226// expected-error@-1{{class template partial specialization is not more specialized than the primary template}}27// expected-error@#Foo2{{'type name' declared as a pointer to a reference of type 'T &'}}28 29 30namespace type_pack {31  template<typename... Args>32  concept C1 = ((sizeof(Args) >= 0) && ...);33 34  template<typename A, typename... B>35  concept C2 = C1<A, B...>;36 37  template<typename T>38  constexpr void foo() requires C2<T, char, T> { }39 40  template<typename T>41  constexpr void foo() requires C1<T, char, T> && true { }42 43  static_assert((foo<int>(), true));44}45 46namespace template_pack {47  template<typename T> struct S1 {};48  template<typename T> struct S2 {};49 50  template<template<typename> typename... Args>51  concept C1 = ((sizeof(Args<int>) >= 0) && ...);52 53  template<template<typename> typename A, template<typename> typename... B>54  concept C2 = C1<A, B...>;55 56  template<template<typename> typename T>57  constexpr void foo() requires C2<T, S1, T> { }58 59  template<template<typename> typename T>60  constexpr void foo() requires C1<T, S1, T> && true { }61 62  static_assert((foo<S2>(), true));63}64 65namespace non_type_pack {66  template<int... Args>67  concept C1 = ((Args >= 0) && ...);68 69  template<int A, int... B>70  concept C2 = C1<A, B...>;71 72  template<int T>73  constexpr void foo() requires C2<T, 2, T> { }74 75  template<int T>76  constexpr void foo() requires C1<T, 2, T> && true { }77 78  static_assert((foo<1>(), true));79}80 81namespace PR47174 {82// This checks that we don't crash with a failed substitution on the first constrained argument when83// performing normalization.84template <Bar2 T, True U> // #S3_Header85requires true struct S3; // expected-note {{template is declared here}}86template <True T, True U>87requires true struct S3<T, U>;88// expected-error@-1 {{class template partial specialization is not more specialized than the primary template}}89// expected-error@#Foo2 2{{'type name' declared as a pointer to a reference of type 'T &'}}90// expected-note@#SpecS2_1 {{while substituting into concept arguments here}}91// expected-note@#SpecS2_2 {{while substituting into concept arguments here}}92// expected-note@#S3_Header {{while substituting into concept arguments here}}93// expected-note@#Bar2 {{while substituting into concept arguments here}}94 95 96// Same as above, for the second position (but this was already working).97template <True T, Bar2 U> // #S4_Header98requires true struct S4; // #S499template <True T, True U>100requires true struct S4<T, U>; // #S4-spec101// expected-error@-1 {{class template partial specialization is not more specialized than the primary template}}102// expected-error@#Foo2 {{'type name' declared as a pointer to a reference of type 'U &'}}103// expected-note@#S4_Header {{while substituting into concept arguments here}}104// expected-note@#S4 {{template is declared here}}105// expected-note@#S4 {{similar constraint expressions not considered equivalent}}106// expected-note@#S4-spec {{similar constraint expression here}}107 108 109 110struct X {111  template<int> struct Y {112    using type = int;113  };114};115 116template<class T> concept C1 = sizeof(T) != 0;117template<class T> concept C2 = C1<typename T::template Y<1>::type>;118 119template<class T> requires C1<T> void t1() {};                // expected-note {{candidate function}}120template<class T> requires C1<T> && C2<T> void t1() = delete; // expected-note {{candidate function}}121template void t1<X>();122void t1() { t1<X>(); } // expected-error {{call to deleted function 't1'}}123 124template<class T> requires C1<T> void t2() {}; // expected-note 2 {{candidate function}}125template<class T> requires C2<T> void t2() {}; // expected-note 2 {{candidate function}}126template void t2<X>(); // expected-error {{partial ordering for explicit instantiation of 't2' is ambiguous}}127void t2() { t2<X>(); } // expected-error {{call to 't2' is ambiguous}}128} // namespace PR47174129