Debian Codegraph @

libstdc++-v3/testsuite/23_containers/span/init_list_cons_neg.cc

raw
1 // { dg-do run { target { c++20 && c++23_down } } }
2 // { dg-do compile { target c++26 } }
3
4 #include <span>
5 #include <utility>
6
7 #include <testsuite_hooks.h>
8
9 struct Any {
10 constexpr Any() { }
11 template<typename T> constexpr Any(T) { }
12 };
13
14 // Examples from P2447R4
15 void one(std::pair<int, int>) {}
16 void one(std::span<const int>) {}
17 void two(std::span<const int, 2>) {}
18 constexpr std::size_t three(std::span<void * const> v) { return v.size(); }
19 constexpr std::size_t four(std::span<const Any> v) { return v.size(); }
20
21 void *array3[10];
22 Any array4[10];
23
24 int main()
25 {
26 one({1, 2}); // { dg-error "call of overloaded" "should be ambiguous with the one(std::pair) overload" { target c++26 } }
27 two({{1, 2}}); // { dg-error "would use explicit constructor" "should prefer the initializer_list constructor, which is explicit" { target c++26 } }
28
29 #if __cpp_lib_span_initializer_list
30 static_assert(three({array3, 0}) == 2);
31 static_assert(four({array4, array4 + 10}) == 2);
32 #else
33 static_assert(three({array3, 0}) == 0);
34 static_assert(four({array4, array4 + 10}) == 10);
35 #endif
36 }