131
|
1 // { dg-do compile { target c++11 } }
|
|
2
|
|
3 #include <initializer_list>
|
|
4
|
|
5 extern "C" int printf (const char *, ...);
|
|
6
|
|
7 using size_t = decltype(sizeof(0));
|
|
8
|
|
9 template <typename T> class ArrayRef {
|
|
10 public:
|
|
11 using size_type = size_t;
|
|
12
|
|
13 private:
|
|
14 /// The start of the array, in an external buffer.
|
|
15 const T *Data = nullptr;
|
|
16
|
|
17 /// The number of elements.
|
|
18 size_type Length = 0;
|
|
19
|
|
20 public:
|
|
21 /// Construct an ArrayRef from a std::initializer_list.
|
|
22 /*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
|
|
23 : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()), // { dg-warning initializer_list }
|
|
24 Length(Vec.size()) {}
|
|
25
|
|
26 const T &operator[](size_t Index) const { return Data[Index]; }
|
|
27 };
|
|
28
|
|
29 int main() {
|
|
30 const ArrayRef<int> Foo = {42};
|
|
31 printf ("Foo %d\n", Foo[0]);
|
|
32 }
|