[Utils] Identity map module-level debug info on first use in CloneFunction* (#118627)
[llvm-project.git] / clang / test / CXX / over / over.match / over.match.best / p1-2a.cpp
blobdb3e3e3bc85966cc0b86334abfa662f1eabd581b
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 // Top-level cv-qualifiers are ignored in template partial ordering per [dcl.fct]/p5.
101 // After producing the list of parameter types, any top-level cv-qualifiers modifying
102 // a parameter type are deleted when forming the function type.
103 template<typename T>
104 constexpr int goo(T a) requires AtLeast2<T> && true {
105 return 1;
108 template<typename T>
109 constexpr int goo(const T b) requires AtLeast2<T> {
110 return 2;
113 // [temp.func.order] p5
114 // Since, in a call context, such type deduction considers only parameters
115 // for which there are explicit call arguments, some parameters are ignored
116 // (namely, function parameter packs, parameters with default arguments, and
117 // ellipsis parameters).
118 template<typename T>
119 constexpr int doo(int a, ...) requires AtLeast2<int> && true {
120 return 1;
123 template<typename T>
124 constexpr int doo(int b) requires AtLeast2<int> {
125 return 2;
128 static_assert(goo<int>(1) == 1);
129 static_assert(doo<int>(2) == 1);