Index: include/array =================================================================== --- include/array +++ include/array @@ -152,31 +152,31 @@ { _VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);} // iterators: - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 iterator begin() _NOEXCEPT {return iterator(__elems_);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_iterator cbegin() const _NOEXCEPT {return begin();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_iterator cend() const _NOEXCEPT {return end();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reverse_iterator crend() const _NOEXCEPT {return rend();} // capacity: @@ -188,23 +188,24 @@ _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} // element access: - _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __elems_[__n];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference operator[](size_type __n) {return __elems_[__n];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference operator[](size_type __n) const {return __elems_[__n];} - reference at(size_type __n); + _LIBCPP_CONSTEXPR_AFTER_CXX11 reference at(size_type __n); _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; - _LIBCPP_INLINE_VISIBILITY reference front() {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference front() {return __elems_[0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];} - _LIBCPP_INLINE_VISIBILITY reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type* data() _NOEXCEPT {return __elems_;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const value_type* data() const _NOEXCEPT {return __elems_;} }; template +_LIBCPP_CONSTEXPR_AFTER_CXX11 typename array<_Tp, _Size>::reference array<_Tp, _Size>::at(size_type __n) { Index: test/std/containers/sequences/array/relaxed_constexpr_members.pass.cpp =================================================================== --- /dev/null +++ test/std/containers/sequences/array/relaxed_constexpr_members.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include + +#include "test_macros.h" + +#if TEST_STD_VER > 11 + +using array = std::array; + +constexpr int test_constexpr_begin() { + array ar = {0, 1, 2}; + array::iterator it = ar.begin(); + ++it; + return *it; +} + +constexpr int test_constexpr_end() { + array ar = {0, 1, 2}; + array::iterator it = ar.end(); + --it; + return *it; +} + +/* rbegin and rend can't be constexpr for now, + * because int the libc++ implementation + * the type reverse_iterator is not literal +constexpr int test_constexpr_rbegin() +{ + array ar = {0, 1, 2}; + array::reverse_iterator it = ar.rbegin(); + ++it; + return *it; +} +constexpr int test_constexpr_rend() +{ + array ar = {0, 1, 2}; + array::reverse_iterator it = ar.rend(); + --it; + return *it; +} +*/ + +constexpr int test_constexpr_front() { + array ar = {0, 1, 2}; + ++ar.front(); + return ar[0]; +} + +constexpr int test_constexpr_back() { + array ar = {0, 1, 2}; + ++ar.back(); + return ar[2]; +} + +constexpr int test_constexpr_data() { + array ar = {0, 1, 2}; + int *p = ar.data(); + *++p = 7; + return ar[1]; +} + +#endif + +int main() { +#if TEST_STD_VER > 11 + { + constexpr int a = test_constexpr_begin(); + static_assert(a == 1, ""); + + constexpr int b = test_constexpr_end(); + static_assert(b == 2, ""); + } + + { + constexpr array ar = {0, 1, 2}; + + constexpr int i1 = ar[1]; + static_assert(i1 == 1, ""); + + constexpr int i2 = ar.at(2); + static_assert(i2 == 2, ""); + } + + { + constexpr int a = test_constexpr_front(); + static_assert(a == 1, ""); + + constexpr int b = test_constexpr_back(); + static_assert(b == 3, ""); + } + + { + constexpr int a = test_constexpr_data(); + static_assert(a == 7, ""); + } +#endif +}