Skip to content

Commit 2172198

Browse files
committed
Addressed comments
1 parent 6c89879 commit 2172198

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

libcxx/test/std/containers/views/views.span/span.cons/initializer_list.pass.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
89
// UNSUPPORTED: c++03, c++11, c++14, c++17
910

1011
// <span>
1112

1213
// constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il); // Since C++26
1314

15+
#include <any>
1416
#include <cassert>
1517
#include <cstddef>
1618
#include <initializer_list>
@@ -89,9 +91,48 @@ constexpr bool test() {
8991
return true;
9092
}
9193

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+
92131
int main(int, char**) {
93-
test();
132+
assert(test());
94133
static_assert(test());
95134

135+
assert(test_P2447R4_annex_c_examples());
136+
96137
return 0;
97138
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}

0 commit comments

Comments
 (0)