1 // RUN: %clang_cc1 -std=c++20 -verify %s
2 // RUN: %clang_cc1 -std=c++17 -verify %s
4 // p0388 conversions to unbounded array
12 #if __cplusplus < 202002
13 // expected-error@-2{{cannot bind to a value of unrelated type}}
19 auto &frob2(int (&arp
)[1]) {
21 #if __cplusplus < 202002
22 // expected-error@-2{{cannot bind to a value of unrelated type}}
34 #if __cplusplus < 202002
35 // expected-error@-2{{with an rvalue of type}}
41 auto *frob2(int (*arp
)[1]) {
43 #if __cplusplus < 202002
44 // expected-error@-2{{with an lvalue of type}}
57 Inc(*const(*r1
)[])[] = &ga
;
58 #if __cplusplus < 202002
59 // expected-error@-2{{with an rvalue of type}}
61 // missing a required 'const'
62 Inc(*(*r2
)[])[] = &ga
; // expected-error{{cannot initialize}}
68 auto *frob2(Mat
*(*arp
)[1]) {
69 Inc(*const(*r2
)[])[] = arp
;
70 #if __cplusplus < 202002
71 // expected-error@-2{{with an lvalue of type}}
73 Inc(*(*r3
)[])[] = arp
; // expected-error{{cannot initialize}}
83 char (&b(int(&&)[]))[1]; // #1
84 char (&b(long(&&)[]))[2]; // #2
85 char (&b(int(&&)[1]))[3]; // #3
86 char (&b(long(&&)[1]))[4]; // #4
87 char (&b(int(&&)[2]))[5]; // #5
88 #if __cplusplus < 202002
89 // expected-note@-6{{cannot convert initializer}}
90 // expected-note@-6{{cannot convert initializer}}
91 // expected-note@-6{{too many initializers}}
92 // expected-note@-6{{too many initializers}}
93 // expected-note@-6{{too many initializers}}
97 static_assert(sizeof(b({1})) == 3);
98 static_assert(sizeof(b({1, 2})) == 5);
99 static_assert(sizeof(b({1, 2, 3})) == 1);
100 #if __cplusplus < 202002
101 // expected-error@-2{{no matching function}}
106 #if __cplusplus >= 202002
108 // from over.ics.rank 3.1
109 char (&f(int(&&)[]))[1]; // #1
110 char (&f(double(&&)[]))[2]; // #2
111 char (&f(int(&&)[2]))[3]; // #3
114 // Calls #1: Better than #2 due to conversion, better than #3 due to bounds
115 static_assert(sizeof(f({1})) == 1);
117 // Calls #2: Identity conversion is better than floating-integral conversion
118 static_assert(sizeof(f({1.0})) == 2);
120 // Calls #2: Identity conversion is better than floating-integral conversion
121 static_assert(sizeof(f({1.0, 2.0})) == 2);
123 // Calls #3: Converting to array of known bound is better than to unknown
124 // bound, and an identity conversion is better than
125 // floating-integral conversion
126 static_assert(sizeof(f({1, 2})) == 3);
133 char (&f(int(&&)[]))[1]; // #1
134 char (&f(double(&&)[1]))[2]; // #2
137 // Calls #2, float-integral conversion rather than create zero-sized array
138 static_assert(sizeof(f({})) == 2);
145 // brace-elision is not a thing here:
150 char (&f1(int(&&)[]))[1]; // #1
151 char (&f1(A(&&)[]))[2]; // #2
154 // pick #1, even though that is more elements than #2
155 // 6 ints, as opposed to 3 As
156 static_assert(sizeof(f1({1, 2, 3, 4, 5, 6})) == 1);
159 void f2(A(&&)[]); // expected-note{{candidate function not viable}}
161 f2({1, 2, 3, 4, 5, 6}); // expected-error{{no matching function}}
168 f({1, 2, 3, 4, 5, 6}); // OK! We're coercing to an already-selected function