1 // RUN: %clang_cc1 -std=c++2a -verify %s
3 template<typename T
, typename U
>
4 constexpr static bool is_same_v
= false;
7 constexpr static bool is_same_v
<T
, T
> = true;
12 concept AtLeast1
= sizeof(T
) >= 1;
15 int foo(T t
) requires (sizeof(T
) == 4) { // expected-note {{candidate function}}
20 char foo(T t
) requires AtLeast1
<T
> { // expected-note {{candidate function}}
25 double foo(T t
) requires (AtLeast1
<T
> && sizeof(T
) <= 2) {
29 static_assert(is_same_v
<decltype(foo(10)), int>); // expected-error {{call to 'foo' is ambiguous}}
30 static_assert(is_same_v
<decltype(foo(short(10))), double>);
33 void bar() requires (sizeof(T
) == 1) { }
34 // expected-note@-1{{similar constraint expressions not considered equivalent}}
35 // expected-note@-2{{candidate function [with T = char]}}
38 void bar() requires (sizeof(T
) == 1 && sizeof(T
) >= 0) { }
39 // expected-note@-1{{candidate function [with T = char]}}
40 // expected-note@-2{{similar constraint expression here}}
42 static_assert(is_same_v
<decltype(bar
<char>()), void>);
43 // expected-error@-1{{call to 'bar' is ambiguous}}
46 constexpr int baz() requires AtLeast1
<T
> { // expected-note {{candidate function}}
50 template<typename T
> requires AtLeast1
<T
>
51 constexpr int baz() { // expected-note {{candidate function [with T = int]}}
55 static_assert(baz
<int>() == 1); // expected-error {{call to 'baz' is ambiguous}}
58 namespace non_template
61 concept AtLeast2
= sizeof(T
) >= 2;
64 concept AtMost8
= sizeof(T
) <= 8;
67 int foo() requires AtLeast2
<long> && AtMost8
<long> {
72 double foo() requires AtLeast2
<long> {
77 double baz() requires AtLeast2
<long> && AtMost8
<long> { // expected-note {{candidate function}}
82 int baz() requires AtMost8
<long> && AtLeast2
<long> { // expected-note {{candidate function}}
87 void bar() requires (sizeof(char[8]) >= 8) { }
88 // expected-note@-1 {{candidate function}}
89 // expected-note@-2 {{similar constraint expressions not considered equivalent}}
92 void bar() requires (sizeof(char[8]) >= 8 && sizeof(int) <= 30) { }
93 // expected-note@-1 {{candidate function}}
94 // expected-note@-2 {{similar constraint expression here}}
96 static_assert(is_same_v
<decltype(foo
<int>()), int>);
97 static_assert(is_same_v
<decltype(baz
<int>()), int>); // expected-error {{call to 'baz' is ambiguous}}
98 static_assert(is_same_v
<decltype(bar
<int>()), void>); // expected-error {{call to 'bar' is ambiguous}}
101 constexpr int goo(int a
) requires AtLeast2
<int> && true { // expected-note {{candidate function}}
106 constexpr int goo(const int b
) requires AtLeast2
<int> { // expected-note {{candidate function}}
110 // [temp.func.order] p5
111 // Since, in a call context, such type deduction considers only parameters
112 // for which there are explicit call arguments, some parameters are ignored
113 // (namely, function parameter packs, parameters with default arguments, and
114 // ellipsis parameters).
116 constexpr int doo(int a
, ...) requires AtLeast2
<int> && true {
121 constexpr int doo(int b
) requires AtLeast2
<int> {
125 // By temp.func.order-6.2.2, this is ambiguous because parameter a and b have different types.
126 static_assert(goo
<int>(1) == 1); // expected-error {{call to 'goo' is ambiguous}}
127 static_assert(doo
<int>(2) == 1);