1 // RUN: %clang_cc1 -std=c++2a -x c++ -verify %s
3 template<typename T
> requires (sizeof(T
) >= 4)
4 // expected-note@-1{{similar constraint expressions not considered equivalent}}
5 bool a() { return false; } // expected-note {{candidate function [with T = unsigned int]}}
7 template<typename T
> requires (sizeof(T
) >= 4 && sizeof(T
) <= 10)
8 // expected-note@-1{{similar constraint expression here}}
9 bool a() { return true; } // expected-note {{candidate function [with T = unsigned int]}}
11 bool av
= a
<unsigned>(); // expected-error {{call to 'a' is ambiguous}}
14 concept C1
= sizeof(T
) >= 4;
16 template<typename T
> requires C1
<T
>
17 constexpr bool b() { return false; }
19 template<typename T
> requires (C1
<T
> && sizeof(T
) <= 10)
20 constexpr bool b() { return true; }
22 static_assert(b
<int>());
23 static_assert(!b
<int[10]>());
26 concept C2
= sizeof(T
) > 1 && sizeof(T
) <= 8;
29 bool c() { return false; }
31 template<typename T
> requires C1
<T
>
32 bool c() { return true; }
34 template<typename T
> requires C1
<T
>
35 constexpr bool d() { return false; }
38 constexpr bool d() { return true; }
40 static_assert(!d
<int>());
43 constexpr int e() { return 1; }
45 template<typename T
> requires C1
<T
> && C2
<T
>
46 constexpr int e() { return 2; }
48 template<typename T
> requires C1
<T
> || C2
<T
>
49 constexpr int e() { return 3; }
51 static_assert(e
<unsigned>() == 2);
52 static_assert(e
<char[10]>() == 3);
53 static_assert(e
<char>() == 1);
55 template<class T
, class U
>
56 concept BiggerThan
= sizeof(T
) > sizeof(U
);
59 concept BiggerThanInt
= BiggerThan
<T
, int>;
61 template<class T
, class U
> requires BiggerThan
<T
, U
>
63 // expected-note@-1 {{candidate function [with T = long long, U = int]}}
65 template<class T
, class U
> requires BiggerThanInt
<T
>
67 // expected-note@-1 {{candidate function [with T = long long, U = int]}}
69 static_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'}}
77 concept C4
= true && C3
<T
>;
79 template<typename T
> requires C3
<void>
82 template<typename T
> requires C4
<void>
85 static_assert(sizeof(g
<int>()));
87 // Regression - used template parameter detection when only first out of
88 // multiple parameters are used
89 template <unsigned> struct X
{};
90 template <class...> int h(X
<0>);
91 template <unsigned b
, class...> int h(X
<b
>);
92 static_assert(sizeof(h(X
<0>{})));