File tree Expand file tree Collapse file tree 2 files changed +90
-1
lines changed
libcxx/test/std/containers/views/views.span/span.cons Expand file tree Collapse file tree 2 files changed +90
-1
lines changed Original file line number Diff line number Diff line change 5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
+
8
9
// UNSUPPORTED: c++03, c++11, c++14, c++17
9
10
10
11
// <span>
11
12
12
13
// constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il); // Since C++26
13
14
15
+ #include < any>
14
16
#include < cassert>
15
17
#include < cstddef>
16
18
#include < initializer_list>
@@ -89,9 +91,48 @@ constexpr bool test() {
89
91
return true ;
90
92
}
91
93
94
+ // Test P2447R4 "Annex C examples"
95
+
96
+ constexpr int three (std::span<void * const > sp) { return sp.size (); }
97
+
98
+ constexpr int four (std::span<const std::any> sp) { return sp.size (); }
99
+
100
+ bool test_P2447R4_annex_c_examples () {
101
+ // 1. Overload resolution is affected
102
+ // --> tested in "initializer_list.verify.cpp"
103
+
104
+ // 2. The `initializer_list` ctor has high precedence
105
+ // --> tested in "initializer_list.verify.cpp"
106
+
107
+ // 3. Implicit two-argument construction with a highly convertible value_type
108
+ #if TEST_STD_VER >= 26
109
+ {
110
+ void * a[10 ];
111
+ assert (three ({a, 0 }) == 2 );
112
+ }
113
+ {
114
+ std::any a[10 ];
115
+ assert (four ({a, a + 10 }) == 2 );
116
+ }
117
+ #else
118
+ {
119
+ void * a[10 ];
120
+ assert (three ({a, 0 }) == 0 );
121
+ }
122
+ {
123
+ std::any a[10 ];
124
+ assert (four ({a, a + 10 }) == 10 );
125
+ }
126
+ #endif
127
+
128
+ return true ;
129
+ }
130
+
92
131
int main (int , char **) {
93
- test ();
132
+ assert ( test () );
94
133
static_assert (test ());
95
134
135
+ assert (test_P2447R4_annex_c_examples ());
136
+
96
137
return 0 ;
97
138
}
Original file line number Diff line number Diff line change
1
+ // ===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ // UNSUPPORTED: c++03, c++11, c++14, c++17
10
+
11
+ // <span>
12
+
13
+ // constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il); // Since C++26
14
+
15
+ #include < span>
16
+ #include < utility>
17
+
18
+ #include " test_macros.h"
19
+
20
+ // Test P2447R4 "Annex C examples"
21
+
22
+ void one (std::pair<int , int >);
23
+ void one (std::span<const int >);
24
+
25
+ void two (std::span<const int , 2 >);
26
+
27
+ void test_P2447R4_annex_c_examples () {
28
+ // 1. Overload resolution is affected
29
+ #if TEST_STD_VER >= 26
30
+ // expected-error@+1 {{call to 'one' is ambiguous}}
31
+ one ({1 , 2 });
32
+ #else
33
+ // expected-no-diagnostics
34
+ one ({1 , 2 });
35
+ #endif
36
+
37
+ // 2. The `initializer_list` ctor has high precedence
38
+ #if TEST_STD_VER >= 26
39
+ // expected-error@+1 {{chosen constructor is explicit in copy-initialization}}
40
+ two ({{1 , 2 }});
41
+ #else
42
+ // expected-no-diagnostics
43
+ two ({{1 , 2 }});
44
+ #endif
45
+
46
+ // 3. Implicit two-argument construction with a highly convertible value_type
47
+ // --> tested in "initializer_list.pass.cpp"
48
+ }
You can’t perform that action at this time.
0 commit comments