diff options
Diffstat (limited to 'clang/test/SemaCXX/constant-expression-cxx1y.cpp')
-rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx1y.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx1y.cpp b/clang/test/SemaCXX/constant-expression-cxx1y.cpp index 40a98d4ca9f..af44bf8d744 100644 --- a/clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx1y.cpp @@ -725,3 +725,43 @@ namespace modify_temporary_during_construction { static_assert(a.y == 54, ""); constexpr int k = a.temporary++; // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}} } + +namespace std { + typedef decltype(sizeof(int)) size_t; + + template <class _E> + class initializer_list + { + const _E* __begin_; + size_t __size_; + + constexpr initializer_list(const _E* __b, size_t __s) + : __begin_(__b), + __size_(__s) + {} + + public: + typedef _E value_type; + typedef const _E& reference; + typedef const _E& const_reference; + typedef size_t size_type; + + typedef const _E* iterator; + typedef const _E* const_iterator; + + constexpr initializer_list() : __begin_(nullptr), __size_(0) {} + + constexpr size_t size() const {return __size_;} + constexpr const _E* begin() const {return __begin_;} + constexpr const _E* end() const {return __begin_ + __size_;} + }; +} + +namespace InitializerList { + constexpr int sum(std::initializer_list<int> ints) { + int total = 0; + for (int n : ints) total += n; + return total; + } + static_assert(sum({1, 2, 3, 4, 5}) == 15, ""); +} |