brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 972a4fd Raw
71 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s2 3template<typename T> requires (sizeof(T) >= 4)4// expected-note@-1{{similar constraint expressions not considered equivalent}}5bool a = false; // expected-note{{template is declared here}}6 7template<typename T> requires (sizeof(T) >= 4 && sizeof(T) <= 10)8// expected-note@-1{{similar constraint expression here}}9bool a<T> = true; // expected-error{{variable template partial specialization is not more specialized than the primary template}}10 11template<typename T>12concept C1 = sizeof(T) >= 4;13 14template<typename T> requires C1<T>15bool b = false;16 17template<typename T> requires (C1<T> && sizeof(T) <= 10)18bool b<T> = true;19 20template<typename T>21concept C2 = sizeof(T) > 1 && sizeof(T) <= 8;22 23template<typename T>24bool c = false;25 26template<typename T> requires C1<T>27bool c<T> = true;28 29template<typename T>30bool d = false;31 32template<typename T>33bool d<T> = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}}34 35template<typename T> requires C1<T>36bool e = false;37 38template<typename T>39bool e<T> = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}}40 41template<typename T>42constexpr int f = 1;43 44template<typename T> requires C1<T> && C2<T>45constexpr int f<T> = 2;46 47template<typename T> requires C1<T> || C2<T>48constexpr int f<T> = 3;49 50static_assert(f<unsigned> == 2);51static_assert(f<char[10]> == 3);52static_assert(f<char> == 1);53 54template <int I>55struct S {56  template <typename T>57  static constexpr int f = 1;58 59  template <typename T>60    requires C1<T> && C2<T>61  static constexpr int f<T> = 2;62 63  template <typename T>64    requires C1<T> || C2<T>65  static constexpr int f<T> = 3;66};67 68static_assert(S<1>::f<unsigned> == 2);69static_assert(S<1>::f<char[10]> == 3);70static_assert(S<1>::f<char> == 1);71