Sebastian Redl | 2b916b8 | 2012-01-17 22:49:42 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
| 2 | |
| 3 | namespace std { |
| 4 | typedef decltype(sizeof(int)) size_t; |
| 5 | |
| 6 | // libc++'s implementation |
| 7 | template <class _E> |
| 8 | class initializer_list |
| 9 | { |
| 10 | const _E* __begin_; |
| 11 | size_t __size_; |
| 12 | |
| 13 | initializer_list(const _E* __b, size_t __s) |
| 14 | : __begin_(__b), |
| 15 | __size_(__s) |
| 16 | {} |
| 17 | |
| 18 | public: |
| 19 | typedef _E value_type; |
| 20 | typedef const _E& reference; |
| 21 | typedef const _E& const_reference; |
| 22 | typedef size_t size_type; |
| 23 | |
| 24 | typedef const _E* iterator; |
| 25 | typedef const _E* const_iterator; |
| 26 | |
| 27 | initializer_list() : __begin_(nullptr), __size_(0) {} |
| 28 | |
| 29 | size_t size() const {return __size_;} |
| 30 | const _E* begin() const {return __begin_;} |
| 31 | const _E* end() const {return __begin_ + __size_;} |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | struct one { char c[1]; }; |
| 36 | struct two { char c[2]; }; |
| 37 | |
| 38 | struct A { |
| 39 | int a, b; |
| 40 | }; |
| 41 | |
| 42 | struct B { |
| 43 | B(); |
| 44 | B(int, int); |
| 45 | }; |
| 46 | |
| 47 | void simple_list() { |
| 48 | std::initializer_list<int> il = { 1, 2, 3 }; |
| 49 | std::initializer_list<double> dl = { 1.0, 2.0, 3 }; |
| 50 | std::initializer_list<A> al = { {1, 2}, {2, 3}, {3, 4} }; |
| 51 | std::initializer_list<B> bl = { {1, 2}, {2, 3}, {} }; |
| 52 | } |
| 53 | |
| 54 | void function_call() { |
| 55 | void f(std::initializer_list<int>); |
| 56 | f({1, 2, 3}); |
| 57 | |
| 58 | void g(std::initializer_list<B>); |
| 59 | g({ {1, 2}, {2, 3}, {} }); |
| 60 | } |