brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 824ec50 Raw
98 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -verify %s2// RUN: %clang_cc1 -std=c++17 -verify %s3 4namespace One {5char (&b(int(&&)[1]))[1]; // #1 expected-note{{too many initializers}}6char (&b(int(&&)[2]))[2]; // #2 expected-note{{too many initializers}}7 8void f() {9  static_assert(sizeof(b({1})) == 1);    // #110  static_assert(sizeof(b({1, 2})) == 2); // #211 12  b({1, 2, 3}); // expected-error{{no matching function}}13}14} // namespace One15 16namespace Two {17struct Bob {18  Bob(int = 1);19};20 21char (&b(Bob(&&)[1]))[1]; // #122char (&b(Bob(&&)[2]))[2]; // #223 24void f() {25  static_assert(sizeof(b({})) == 1);         // #126  static_assert(sizeof(b({Bob()})) == 1);    // #127  static_assert(sizeof(b({2, Bob()})) == 2); // #228}29} // namespace Two30 31namespace Three {32struct Kevin {33  Kevin(int);34};35 36char (&b(Kevin(&&)[2]))[2]; // #2 expected-note{{too few initializers}}37 38void f() {39  b({2}); // #1 expected-error{{no matching function}}40}41} // namespace Three42 43namespace Four {44char (&b(int(&&)[1], float))[1];  // #1 expected-note{{candidate}}45char (&b(int(&&)[1], double))[2]; // #2 expected-note{{candidate}}46 47char (&c(float, int(&&)[1]))[1];  // #1 expected-note{{candidate}}48char (&c(double, int(&&)[1]))[2]; // #2 expected-note{{candidate}}49 50void f() {51  b({1}, 0); // expected-error{{is ambiguous}}52  c(0, {1}); // expected-error{{is ambiguous}}53}54} // namespace Four55 56typedef decltype(sizeof(char)) size_t;57namespace std {58// sufficient initializer list59template <class _E>60class initializer_list {61  const _E *__begin_;62  size_t __size_;63 64  constexpr initializer_list(const _E *__b, size_t __s)65      : __begin_(__b),66        __size_(__s) {}67 68public:69  typedef _E value_type;70  typedef const _E &reference;71  typedef const _E &const_reference;72  typedef size_t size_type;73 74  typedef const _E *iterator;75  typedef const _E *const_iterator;76 77  constexpr initializer_list() : __begin_(nullptr), __size_(0) {}78 79  constexpr size_t size() const { return __size_; }80  constexpr const _E *begin() const { return __begin_; }81  constexpr const _E *end() const { return __begin_ + __size_; }82};83} // namespace std84 85namespace Five {86struct ugly {87  ugly(char *);88  ugly(int);89};90char (&f(std::initializer_list<char *>))[1]; // #191char (&f(std::initializer_list<ugly>))[2];   // #292void g() {93  // Pick #2 as #1 not viable (3->char * fails).94  static_assert(sizeof(f({"hello", 3})) == 2); // expected-warning{{not allow}}95}96 97} // namespace Five98