brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · b2fe2cd Raw
93 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() { return false; } // expected-note {{candidate function [with T = unsigned int]}}6 7template<typename T> requires (sizeof(T) >= 4 && sizeof(T) <= 10)8// expected-note@-1{{similar constraint expression here}}9bool a() { return true; } // expected-note {{candidate function [with T = unsigned int]}}10 11bool av = a<unsigned>(); // expected-error {{call to 'a' is ambiguous}}12 13template<typename T>14concept C1 = sizeof(T) >= 4;15 16template<typename T> requires C1<T>17constexpr bool b() { return false; }18 19template<typename T> requires (C1<T> && sizeof(T) <= 10)20constexpr bool b() { return true; }21 22static_assert(b<int>());23static_assert(!b<int[10]>());24 25template<typename T>26concept C2 = sizeof(T) > 1 && sizeof(T) <= 8;27 28template<typename T>29bool c() { return false; }30 31template<typename T> requires C1<T>32bool c() { return true; }33 34template<typename T> requires C1<T>35constexpr bool d() { return false; }36 37template<typename T>38constexpr bool d() { return true; }39 40static_assert(!d<int>());41 42template<typename T>43constexpr int e() { return 1; }44 45template<typename T> requires C1<T> && C2<T>46constexpr int e() { return 2; }47 48template<typename T> requires C1<T> || C2<T>49constexpr int e() { return 3; }50 51static_assert(e<unsigned>() == 2);52static_assert(e<char[10]>() == 3);53static_assert(e<char>() == 1);54 55template<class T, class U>56concept BiggerThan = sizeof(T) > sizeof(U);57 58template<class T>59concept BiggerThanInt = BiggerThan<T, int>;60 61template<class T, class U> requires BiggerThan<T, U>62void f() { }63// expected-note@-1 {{candidate function [with T = long long, U = int]}}64 65template<class T, class U> requires BiggerThanInt<T>66void f() { }67// expected-note@-1 {{candidate function [with T = long long, U = int]}}68 69static_assert(sizeof(f<long long, int>()));70// expected-error@-1 {{call to 'f' is ambiguous}} \71   expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}}72 73template<typename T>74concept C3 = true;75 76template<typename T>77concept C4 = true && C3<T>;78 79template<typename T> requires C3<void>80int g() { }81 82template<typename T> requires C4<void>83int g() { }84 85static_assert(sizeof(g<int>()));86 87// Regression - used template parameter detection when only first out of88// multiple parameters are used89template <unsigned> struct X {};90template <class...> int h(X<0>);91template <unsigned b, class...> int h(X<b>);92static_assert(sizeof(h(X<0>{})));93