Sebastian Redl | ce7cd26 | 2011-05-20 21:07:01 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s |
| 2 | // XFAIL: * |
| 3 | |
| 4 | template <typename T, typename U> |
| 5 | struct same_type { static const bool value = false; }; |
| 6 | template <typename T> |
| 7 | struct same_type<T, T> { static const bool value = true; }; |
| 8 | |
| 9 | namespace std { |
| 10 | typedef decltype(sizeof(int)) size_t; |
| 11 | |
| 12 | // libc++'s implementation |
| 13 | template <class _E> |
| 14 | class initializer_list |
| 15 | { |
| 16 | const _E* __begin_; |
| 17 | size_t __size_; |
| 18 | |
| 19 | initializer_list(const _E* __b, size_t __s) |
| 20 | : __begin_(__b), |
| 21 | __size_(__s) |
| 22 | {} |
| 23 | |
| 24 | public: |
| 25 | typedef _E value_type; |
| 26 | typedef const _E& reference; |
| 27 | typedef const _E& const_reference; |
| 28 | typedef size_t size_type; |
| 29 | |
| 30 | typedef const _E* iterator; |
| 31 | typedef const _E* const_iterator; |
| 32 | |
| 33 | initializer_list() : __begin_(nullptr), __size_(0) {} |
| 34 | |
| 35 | size_t size() const {return __size_;} |
| 36 | const _E* begin() const {return __begin_;} |
| 37 | const _E* end() const {return __begin_ + __size_;} |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | namespace integral { |
| 42 | |
| 43 | void initialization() { |
| 44 | { const int a{}; static_assert(a == 0, ""); } |
| 45 | { const int a = {}; static_assert(a == 0, ""); } |
| 46 | { const int a{1}; static_assert(a == 1, ""); } |
| 47 | { const int a = {1}; static_assert(a == 1, ""); } |
| 48 | { const int a{1, 2}; } // expected-error {{ too many initializers}} |
| 49 | { const int a = {1, 2}; } // expected-error {{ too many initializers}} |
| 50 | { const short a = {100000}; } // expected-error {{narrowing conversion}} |
| 51 | } |
| 52 | |
| 53 | int function_call() { |
| 54 | void takes_int(int); |
| 55 | takes_int({1}); |
| 56 | |
| 57 | int ar[10]; |
| 58 | (void) ar[{1}]; // expected-error {{initializer list is illegal with the built-in index operator}} |
| 59 | |
| 60 | return {1}; |
| 61 | } |
| 62 | |
| 63 | void inline_init() { |
| 64 | (void) int{1}; |
| 65 | (void) new int{1}; |
| 66 | } |
| 67 | |
| 68 | void initializer_list() { |
| 69 | auto l = {1, 2, 3, 4}; |
| 70 | static_assert(same_type<decltype(l), std::initializer_list<int>>::value, ""); |
| 71 | |
| 72 | for (int i : {1, 2, 3, 4}) {} |
| 73 | } |
| 74 | |
| 75 | struct A { |
| 76 | int i; |
| 77 | A() : i{1} {} |
| 78 | }; |
| 79 | |
| 80 | } |
| 81 | |
| 82 | namespace objects { |
| 83 | |
| 84 | struct A { |
| 85 | A(); |
| 86 | A(int, double); |
| 87 | A(int, int); |
| 88 | A(std::initializer_list<int>); |
| 89 | |
| 90 | int operator[](A); |
| 91 | }; |
| 92 | |
| 93 | void initialization() { |
| 94 | // FIXME: how to ensure correct overloads are called? |
| 95 | { A a{}; } |
| 96 | { A a = {}; } |
| 97 | { A a{1, 1.0}; } |
| 98 | { A a = {1, 1.0}; } |
| 99 | { A a{1, 2, 3, 4, 5, 6, 7, 8}; } |
| 100 | { A a = {1, 2, 3, 4, 5, 6, 7, 8}; } |
| 101 | { A a{1, 2, 3, 4, 5, 6, 7, 8}; } |
| 102 | { A a{1, 2}; } |
| 103 | } |
| 104 | |
| 105 | A function_call() { |
| 106 | void takes_A(A); |
| 107 | takes_a({1, 1.0}); |
| 108 | |
| 109 | A a; |
| 110 | a[{1, 1.0}]; |
| 111 | |
| 112 | return {1, 1.0}; |
| 113 | } |
| 114 | |
| 115 | void inline_init() { |
| 116 | (void) A{1, 1.0}; |
| 117 | (void) new A{1, 1.0}; |
| 118 | } |
| 119 | |
| 120 | struct B { |
| 121 | B(A, int, A); |
| 122 | }; |
| 123 | |
| 124 | void nested_init() { |
| 125 | B b{{1, 1.0}, 2, {3, 4, 5, 6, 7}}; |
| 126 | } |
| 127 | } |