Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / over / over.match / over.match.best / p1-2a.cpp
blobdae1ba760cc2035e2b9547a36b47d593f21ebea7
1 // RUN: %clang_cc1 -std=c++2a -verify %s
3 template<typename T, typename U>
4 constexpr static bool is_same_v = false;
6 template<typename T>
7 constexpr static bool is_same_v<T, T> = true;
9 namespace templates
11 template<typename T>
12 concept AtLeast1 = sizeof(T) >= 1;
14 template<typename T>
15 int foo(T t) requires (sizeof(T) == 4) { // expected-note {{candidate function}}
16 return 0;
19 template<typename T>
20 char foo(T t) requires AtLeast1<T> { // expected-note {{candidate function}}
21 return 'a';
24 template<typename T>
25 double foo(T t) requires (AtLeast1<T> && sizeof(T) <= 2) {
26 return 'a';
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>);
32 template<typename T>
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]}}
37 template<typename T>
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}}
45 template<typename T>
46 constexpr int baz() requires AtLeast1<T> { // expected-note {{candidate function}}
47 return 1;
50 template<typename T> requires AtLeast1<T>
51 constexpr int baz() { // expected-note {{candidate function [with T = int]}}
52 return 2;
55 static_assert(baz<int>() == 1); // expected-error {{call to 'baz' is ambiguous}}
58 namespace non_template
60 template<typename T>
61 concept AtLeast2 = sizeof(T) >= 2;
63 template<typename T>
64 concept AtMost8 = sizeof(T) <= 8;
66 template<typename T>
67 int foo() requires AtLeast2<long> && AtMost8<long> {
68 return 0;
71 template<typename T>
72 double foo() requires AtLeast2<long> {
73 return 0.0;
76 template<typename T>
77 double baz() requires AtLeast2<long> && AtMost8<long> { // expected-note {{candidate function}}
78 return 0.0;
81 template<typename T>
82 int baz() requires AtMost8<long> && AtLeast2<long> { // expected-note {{candidate function}}
83 return 0.0;
86 template<typename T>
87 void bar() requires (sizeof(char[8]) >= 8) { }
88 // expected-note@-1 {{candidate function}}
89 // expected-note@-2 {{similar constraint expressions not considered equivalent}}
91 template<typename T>
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}}
100 template<typename T>
101 constexpr int goo(int a) requires AtLeast2<int> && true { // expected-note {{candidate function}}
102 return 1;
105 template<typename T>
106 constexpr int goo(const int b) requires AtLeast2<int> { // expected-note {{candidate function}}
107 return 2;
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).
115 template<typename T>
116 constexpr int doo(int a, ...) requires AtLeast2<int> && true {
117 return 1;
120 template<typename T>
121 constexpr int doo(int b) requires AtLeast2<int> {
122 return 2;
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);