From 06db992005654ed7993b9f7696e2c34751f82db2 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 23 Aug 2016 11:13:12 +0100 Subject: [PATCH] Add constexpr to and for C++17 * include/bits/c++config (_GLIBCXX17_CONSTEXPR): Define. * include/bits/range_access.h (begin, end, rbegin, rend, crbegin) (crend): Add _GLIBCXX17_CONSTEXPR as per P0031R0. * include/bits/stl_iterator.h (reverse_iterator, move_iterator) (__make_reverse_iterator, make_reverse_iterator, make_move_iterator): Likewise. * include/bits/stl_iterator_base_funcs.h (__distance, __advance): Add _GLIBCXX14_CONSTEXPR. (distance, advance, next, prev): Add _GLIBCXX17_CONSTEXPR. * include/std/array (array::begin, array::end, array::rbegin) (array::rend, array::cbegin, array:cend, array::crbegin) (array::crend, array::operator[], array::at, array::front) (array::back, array::data): Likewise. * testsuite/24_iterators/headers/iterator/range_access.cc: Replace with separate tests for C++11, C++14, and C++17. * testsuite/24_iterators/headers/iterator/range_access_c++11.cc: New. * testsuite/24_iterators/headers/iterator/range_access_c++14.cc: New. * testsuite/24_iterators/headers/iterator/range_access_c++17.cc: New. From-SVN: r239690 --- libstdc++-v3/ChangeLog | 21 +++ libstdc++-v3/include/bits/c++config | 8 ++ libstdc++-v3/include/bits/range_access.h | 28 ++-- libstdc++-v3/include/bits/stl_iterator.h | 132 ++++++++++-------- .../include/bits/stl_iterator_base_funcs.h | 21 +-- libstdc++-v3/include/std/array | 36 ++--- ...{range_access.cc => range_access_c++11.cc} | 8 +- .../headers/iterator/range_access_c++14.cc | 57 ++++++++ .../headers/iterator/range_access_c++17.cc | 57 ++++++++ .../ext/profile/mutex_extensions_neg.cc | 2 +- 10 files changed, 261 insertions(+), 109 deletions(-) rename libstdc++-v3/testsuite/24_iterators/headers/iterator/{range_access.cc => range_access_c++11.cc} (84%) create mode 100644 libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++14.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++17.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2e88e398b2a..ab0c91b3e5e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,24 @@ +2016-08-23 Jonathan Wakely + + * include/bits/c++config (_GLIBCXX17_CONSTEXPR): Define. + * include/bits/range_access.h (begin, end, rbegin, rend, crbegin) + (crend): Add _GLIBCXX17_CONSTEXPR as per P0031R0. + * include/bits/stl_iterator.h (reverse_iterator, move_iterator) + (__make_reverse_iterator, make_reverse_iterator, make_move_iterator): + Likewise. + * include/bits/stl_iterator_base_funcs.h (__distance, __advance): Add + _GLIBCXX14_CONSTEXPR. + (distance, advance, next, prev): Add _GLIBCXX17_CONSTEXPR. + * include/std/array (array::begin, array::end, array::rbegin) + (array::rend, array::cbegin, array:cend, array::crbegin) + (array::crend, array::operator[], array::at, array::front) + (array::back, array::data): Likewise. + * testsuite/24_iterators/headers/iterator/range_access.cc: Replace + with separate tests for C++11, C++14, and C++17. + * testsuite/24_iterators/headers/iterator/range_access_c++11.cc: New. + * testsuite/24_iterators/headers/iterator/range_access_c++14.cc: New. + * testsuite/24_iterators/headers/iterator/range_access_c++17.cc: New. + 2016-08-22 Tim Shen Split _M_dfs() into smaller functions. diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 8d2c3612afd..656ef781012 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -111,6 +111,14 @@ # endif #endif +#ifndef _GLIBCXX17_CONSTEXPR +# if __cplusplus > 201402L +# define _GLIBCXX17_CONSTEXPR constexpr +# else +# define _GLIBCXX17_CONSTEXPR +# endif +#endif + // Macro for noexcept, to support in mixed 03/0x mode. #ifndef _GLIBCXX_NOEXCEPT # if __cplusplus >= 201103L diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h index d6f8fa15f0f..27cc8ede458 100644 --- a/libstdc++-v3/include/bits/range_access.h +++ b/libstdc++-v3/include/bits/range_access.h @@ -48,7 +48,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto begin(_Container& __cont) -> decltype(__cont.begin()) { return __cont.begin(); } @@ -58,7 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto begin(const _Container& __cont) -> decltype(__cont.begin()) { return __cont.begin(); } @@ -68,7 +68,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto end(_Container& __cont) -> decltype(__cont.end()) { return __cont.end(); } @@ -78,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto end(const _Container& __cont) -> decltype(__cont.end()) { return __cont.end(); } @@ -138,7 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto rbegin(_Container& __cont) -> decltype(__cont.rbegin()) { return __cont.rbegin(); } @@ -148,7 +148,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto rbegin(const _Container& __cont) -> decltype(__cont.rbegin()) { return __cont.rbegin(); } @@ -158,7 +158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto rend(_Container& __cont) -> decltype(__cont.rend()) { return __cont.rend(); } @@ -168,7 +168,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto rend(const _Container& __cont) -> decltype(__cont.rend()) { return __cont.rend(); } @@ -178,7 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template - inline reverse_iterator<_Tp*> + inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*> rbegin(_Tp (&__arr)[_Nm]) { return reverse_iterator<_Tp*>(__arr + _Nm); } @@ -188,7 +188,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template - inline reverse_iterator<_Tp*> + inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*> rend(_Tp (&__arr)[_Nm]) { return reverse_iterator<_Tp*>(__arr); } @@ -198,7 +198,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il initializer_list. */ template - inline reverse_iterator + inline _GLIBCXX17_CONSTEXPR reverse_iterator rbegin(initializer_list<_Tp> __il) { return reverse_iterator(__il.end()); } @@ -208,7 +208,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il initializer_list. */ template - inline reverse_iterator + inline _GLIBCXX17_CONSTEXPR reverse_iterator rend(initializer_list<_Tp> __il) { return reverse_iterator(__il.begin()); } @@ -218,7 +218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont)) { return std::rbegin(__cont); } @@ -228,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template - inline auto + inline _GLIBCXX17_CONSTEXPR auto crend(const _Container& __cont) -> decltype(std::rend(__cont)) { return std::rend(__cont); } diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 3401cd0fb73..037e9661f6c 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -65,6 +65,10 @@ #include #include +#if __cplusplus > 201402L +# define __cpp_lib_array_constexpr 201603 +#endif + namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -118,17 +122,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ // _GLIBCXX_RESOLVE_LIB_DEFECTS // 235 No specification of default ctor for reverse_iterator + _GLIBCXX17_CONSTEXPR reverse_iterator() : current() { } /** * This %iterator will move in the opposite direction that @p x does. */ - explicit + explicit _GLIBCXX17_CONSTEXPR reverse_iterator(iterator_type __x) : current(__x) { } /** * The copy constructor is normal. */ + _GLIBCXX17_CONSTEXPR reverse_iterator(const reverse_iterator& __x) : current(__x.current) { } @@ -137,13 +143,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * underlying %iterator can be converted to the type of @c current. */ template + _GLIBCXX17_CONSTEXPR reverse_iterator(const reverse_iterator<_Iter>& __x) : current(__x.base()) { } /** * @return @c current, the %iterator used for underlying work. */ - iterator_type + _GLIBCXX17_CONSTEXPR iterator_type base() const { return current; } @@ -157,7 +164,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @c *x remains valid after @c x has been modified or * destroyed. This is a bug: http://gcc.gnu.org/PR51823 */ - reference + _GLIBCXX17_CONSTEXPR reference operator*() const { _Iterator __tmp = current; @@ -169,7 +176,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * This requires that @c --current is dereferenceable. */ - pointer + _GLIBCXX17_CONSTEXPR pointer operator->() const { return &(operator*()); } @@ -178,7 +185,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * Decrements the underlying iterator. */ - reverse_iterator& + _GLIBCXX17_CONSTEXPR reverse_iterator& operator++() { --current; @@ -190,7 +197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * Decrements the underlying iterator. */ - reverse_iterator + _GLIBCXX17_CONSTEXPR reverse_iterator operator++(int) { reverse_iterator __tmp = *this; @@ -203,7 +210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * Increments the underlying iterator. */ - reverse_iterator& + _GLIBCXX17_CONSTEXPR reverse_iterator& operator--() { ++current; @@ -215,7 +222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * Increments the underlying iterator. */ - reverse_iterator + _GLIBCXX17_CONSTEXPR reverse_iterator operator--(int) { reverse_iterator __tmp = *this; @@ -228,7 +235,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ - reverse_iterator + _GLIBCXX17_CONSTEXPR reverse_iterator operator+(difference_type __n) const { return reverse_iterator(current - __n); } @@ -238,7 +245,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Moves the underlying iterator backwards @a __n steps. * The underlying iterator must be a Random Access Iterator. */ - reverse_iterator& + _GLIBCXX17_CONSTEXPR reverse_iterator& operator+=(difference_type __n) { current -= __n; @@ -250,7 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ - reverse_iterator + _GLIBCXX17_CONSTEXPR reverse_iterator operator-(difference_type __n) const { return reverse_iterator(current + __n); } @@ -260,7 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Moves the underlying iterator forwards @a __n steps. * The underlying iterator must be a Random Access Iterator. */ - reverse_iterator& + _GLIBCXX17_CONSTEXPR reverse_iterator& operator-=(difference_type __n) { current += __n; @@ -272,7 +279,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ - reference + _GLIBCXX17_CONSTEXPR reference operator[](difference_type __n) const { return *(*this + __n); } }; @@ -288,49 +295,50 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * */ template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator==(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __x.base() == __y.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y.base() < __x.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator!=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__x == __y); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y < __x; } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__y < __x); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__x < __y); } template - inline typename reverse_iterator<_Iterator>::difference_type + inline _GLIBCXX17_CONSTEXPR + typename reverse_iterator<_Iterator>::difference_type operator-(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y.base() - __x.base(); } template - inline reverse_iterator<_Iterator> + inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> operator+(typename reverse_iterator<_Iterator>::difference_type __n, const reverse_iterator<_Iterator>& __x) { return reverse_iterator<_Iterator>(__x.base() - __n); } @@ -338,37 +346,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 280. Comparison of reverse_iterator to const reverse_iterator. template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator==(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() == __y.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __y.base() < __x.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator!=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return !(__x == __y); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __y < __x; } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return !(__y < __x); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return !(__x < __y); } @@ -376,7 +384,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template #if __cplusplus >= 201103L // DR 685. - inline auto + inline _GLIBCXX17_CONSTEXPR auto operator-(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) -> decltype(__y.base() - __x.base()) @@ -391,7 +399,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus >= 201103L // Same as C++14 make_reverse_iterator but used in C++03 mode too. template - inline reverse_iterator<_Iterator> + inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> __make_reverse_iterator(_Iterator __i) { return reverse_iterator<_Iterator>(__i); } @@ -402,7 +410,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 2285. make_reverse_iterator /// Generator function for reverse_iterator. template - inline reverse_iterator<_Iterator> + inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> make_reverse_iterator(_Iterator __i) { return reverse_iterator<_Iterator>(__i); } # endif @@ -1018,37 +1026,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename remove_reference<__base_ref>::type&&, __base_ref>::type reference; + _GLIBCXX17_CONSTEXPR move_iterator() : _M_current() { } - explicit + explicit _GLIBCXX17_CONSTEXPR move_iterator(iterator_type __i) : _M_current(__i) { } template + _GLIBCXX17_CONSTEXPR move_iterator(const move_iterator<_Iter>& __i) : _M_current(__i.base()) { } - iterator_type + _GLIBCXX17_CONSTEXPR iterator_type base() const { return _M_current; } - reference + _GLIBCXX17_CONSTEXPR reference operator*() const { return static_cast(*_M_current); } - pointer + _GLIBCXX17_CONSTEXPR pointer operator->() const { return _M_current; } - move_iterator& + _GLIBCXX17_CONSTEXPR move_iterator& operator++() { ++_M_current; return *this; } - move_iterator + _GLIBCXX17_CONSTEXPR move_iterator operator++(int) { move_iterator __tmp = *this; @@ -1056,14 +1066,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __tmp; } - move_iterator& + _GLIBCXX17_CONSTEXPR move_iterator& operator--() { --_M_current; return *this; } - move_iterator + _GLIBCXX17_CONSTEXPR move_iterator operator--(int) { move_iterator __tmp = *this; @@ -1071,29 +1081,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __tmp; } - move_iterator + _GLIBCXX17_CONSTEXPR move_iterator operator+(difference_type __n) const { return move_iterator(_M_current + __n); } - move_iterator& + _GLIBCXX17_CONSTEXPR move_iterator& operator+=(difference_type __n) { _M_current += __n; return *this; } - move_iterator + _GLIBCXX17_CONSTEXPR move_iterator operator-(difference_type __n) const { return move_iterator(_M_current - __n); } - move_iterator& + _GLIBCXX17_CONSTEXPR move_iterator& operator-=(difference_type __n) { _M_current -= __n; return *this; } - reference + _GLIBCXX17_CONSTEXPR reference operator[](difference_type __n) const { return std::move(_M_current[__n]); } }; @@ -1102,100 +1112,100 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // why there are always 2 versions for most of the move_iterator // operators. template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator==(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __x.base() == __y.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator==(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __x.base() == __y.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator!=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return !(__x == __y); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator!=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return !(__x == __y); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __x.base() < __y.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __x.base() < __y.base(); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return !(__y < __x); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator<=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return !(__y < __x); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __y < __x; } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __y < __x; } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return !(__x < __y); } template - inline bool + inline _GLIBCXX17_CONSTEXPR bool operator>=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return !(__x < __y); } // DR 685. template - inline auto + inline _GLIBCXX17_CONSTEXPR auto operator-(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) -> decltype(__x.base() - __y.base()) { return __x.base() - __y.base(); } template - inline auto + inline _GLIBCXX17_CONSTEXPR auto operator-(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) -> decltype(__x.base() - __y.base()) { return __x.base() - __y.base(); } template - inline move_iterator<_Iterator> + inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> operator+(typename move_iterator<_Iterator>::difference_type __n, const move_iterator<_Iterator>& __x) { return __x + __n; } template - inline move_iterator<_Iterator> + inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> make_move_iterator(_Iterator __i) { return move_iterator<_Iterator>(__i); } @@ -1203,7 +1213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = typename conditional<__move_if_noexcept_cond ::value_type>::value, _Iterator, move_iterator<_Iterator>>::type> - inline _ReturnType + inline _GLIBCXX17_CONSTEXPR _ReturnType __make_move_if_noexcept_iterator(_Iterator __i) { return _ReturnType(__i); } @@ -1212,7 +1222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template::value, const _Tp*, move_iterator<_Tp*>>::type> - inline _ReturnType + inline _GLIBCXX17_CONSTEXPR _ReturnType __make_move_if_noexcept_iterator(_Tp* __i) { return _ReturnType(__i); } diff --git a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h index a8b156d1ec7..1fc646cf3d9 100644 --- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h +++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h @@ -75,7 +75,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER _GLIBCXX_BEGIN_NAMESPACE_VERSION template - inline typename iterator_traits<_InputIterator>::difference_type + inline _GLIBCXX14_CONSTEXPR + typename iterator_traits<_InputIterator>::difference_type __distance(_InputIterator __first, _InputIterator __last, input_iterator_tag) { @@ -92,7 +93,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename iterator_traits<_RandomAccessIterator>::difference_type + inline _GLIBCXX14_CONSTEXPR + typename iterator_traits<_RandomAccessIterator>::difference_type __distance(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) { @@ -131,7 +133,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * and are constant time. For other %iterator classes they are linear time. */ template - inline typename iterator_traits<_InputIterator>::difference_type + inline _GLIBCXX17_CONSTEXPR + typename iterator_traits<_InputIterator>::difference_type distance(_InputIterator __first, _InputIterator __last) { // concept requirements -- taken care of in __distance @@ -140,7 +143,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline void + inline _GLIBCXX14_CONSTEXPR void __advance(_InputIterator& __i, _Distance __n, input_iterator_tag) { // concept requirements @@ -151,7 +154,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline void + inline _GLIBCXX14_CONSTEXPR void __advance(_BidirectionalIterator& __i, _Distance __n, bidirectional_iterator_tag) { @@ -167,7 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline void + inline _GLIBCXX14_CONSTEXPR void __advance(_RandomAccessIterator& __i, _Distance __n, random_access_iterator_tag) { @@ -190,7 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * and are constant time. For other %iterator classes they are linear time. */ template - inline void + inline _GLIBCXX17_CONSTEXPR void advance(_InputIterator& __i, _Distance __n) { // concept requirements -- taken care of in __advance @@ -201,7 +204,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus >= 201103L template - inline _ForwardIterator + inline _GLIBCXX17_CONSTEXPR _ForwardIterator next(_ForwardIterator __x, typename iterator_traits<_ForwardIterator>::difference_type __n = 1) { @@ -213,7 +216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline _BidirectionalIterator + inline _GLIBCXX17_CONSTEXPR _BidirectionalIterator prev(_BidirectionalIterator __x, typename iterator_traits<_BidirectionalIterator>::difference_type __n = 1) { diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index 73a6fbce4f3..3ab0355cf08 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -122,51 +122,51 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { std::swap_ranges(begin(), end(), __other.begin()); } // Iterators. - iterator + _GLIBCXX17_CONSTEXPR iterator begin() noexcept { return iterator(data()); } - const_iterator + _GLIBCXX17_CONSTEXPR const_iterator begin() const noexcept { return const_iterator(data()); } - iterator + _GLIBCXX17_CONSTEXPR iterator end() noexcept { return iterator(data() + _Nm); } - const_iterator + _GLIBCXX17_CONSTEXPR const_iterator end() const noexcept { return const_iterator(data() + _Nm); } - reverse_iterator + _GLIBCXX17_CONSTEXPR reverse_iterator rbegin() noexcept { return reverse_iterator(end()); } - const_reverse_iterator + _GLIBCXX17_CONSTEXPR const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } - reverse_iterator + _GLIBCXX17_CONSTEXPR reverse_iterator rend() noexcept { return reverse_iterator(begin()); } - const_reverse_iterator + _GLIBCXX17_CONSTEXPR const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } - const_iterator + _GLIBCXX17_CONSTEXPR const_iterator cbegin() const noexcept { return const_iterator(data()); } - const_iterator + _GLIBCXX17_CONSTEXPR const_iterator cend() const noexcept { return const_iterator(data() + _Nm); } - const_reverse_iterator + _GLIBCXX17_CONSTEXPR const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } - const_reverse_iterator + _GLIBCXX17_CONSTEXPR const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -181,7 +181,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER empty() const noexcept { return size() == 0; } // Element access. - reference + _GLIBCXX17_CONSTEXPR reference operator[](size_type __n) noexcept { return _AT_Type::_S_ref(_M_elems, __n); } @@ -189,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER operator[](size_type __n) const noexcept { return _AT_Type::_S_ref(_M_elems, __n); } - reference + _GLIBCXX17_CONSTEXPR reference at(size_type __n) { if (__n >= _Nm) @@ -211,7 +211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _AT_Type::_S_ref(_M_elems, 0)); } - reference + _GLIBCXX17_CONSTEXPR reference front() noexcept { return *begin(); } @@ -219,7 +219,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER front() const noexcept { return _AT_Type::_S_ref(_M_elems, 0); } - reference + _GLIBCXX17_CONSTEXPR reference back() noexcept { return _Nm ? *(end() - 1) : *end(); } @@ -230,11 +230,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER : _AT_Type::_S_ref(_M_elems, 0); } - pointer + _GLIBCXX17_CONSTEXPR pointer data() noexcept { return _AT_Type::_S_ptr(_M_elems); } - const_pointer + _GLIBCXX17_CONSTEXPR const_pointer data() const noexcept { return _AT_Type::_S_ptr(_M_elems); } }; diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++11.cc similarity index 84% rename from libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc rename to libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++11.cc index 873a730274e..6961a208834 100644 --- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access.cc +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++11.cc @@ -1,4 +1,5 @@ -// { dg-do compile { target c++11 } } +// { dg-options "-std=gnu++11" } +// { dg-do compile } // Copyright (C) 2010-2016 Free Software Foundation, Inc. // @@ -27,11 +28,6 @@ namespace std template auto end(C& c) -> decltype(c.end()); template auto end(const C& c) -> decltype(c.end()); -#if __cplusplus >= 201402L - template constexpr T* begin(T (&array)[N]); - template constexpr T* end(T (&array)[N]); -#else template T* begin(T (&array)[N]); template T* end(T (&array)[N]); -#endif } diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++14.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++14.cc new file mode 100644 index 00000000000..6f39b56323e --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++14.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +namespace std +{ + template auto begin(C& c) -> decltype(c.begin()); + template auto begin(const C& c) -> decltype(c.begin()); + + template auto end(C& c) -> decltype(c.end()); + template auto end(const C& c) -> decltype(c.end()); + + template constexpr T* begin(T (&array)[N]); + template constexpr T* end(T (&array)[N]); + + template auto cbegin(const C& c) -> decltype(c.begin()); + template auto cend(const C& c) -> decltype(c.end()); + + template auto rbegin(C& c) -> decltype(c.rbegin()); + template auto rbegin(const C& c) -> decltype(c.rbegin()); + + template auto rend(C& c) -> decltype(c.rend()); + template auto rend(const C& c) -> decltype(c.rend()); + + template + reverse_iterator rbegin(T (&array)[N]); + template + reverse_iterator rend(T (&array)[N]); + + template + reverse_iterator rbegin(initializer_list); + template + reverse_iterator rend(initializer_list); + + template + auto crbegin(const C& c) -> decltype(std::rbegin(c)); + template + auto cend(const C& c) -> decltype(std::rend(c)); +} diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++17.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++17.cc new file mode 100644 index 00000000000..3318809f3e7 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/range_access_c++17.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +namespace std +{ + template constexpr auto begin(C& c) -> decltype(c.begin()); + template constexpr auto begin(const C& c) -> decltype(c.begin()); + + template constexpr auto end(C& c) -> decltype(c.end()); + template constexpr auto end(const C& c) -> decltype(c.end()); + + template constexpr T* begin(T (&array)[N]); + template constexpr T* end(T (&array)[N]); + + template constexpr auto cbegin(const C& c) -> decltype(c.begin()); + template constexpr auto cend(const C& c) -> decltype(c.end()); + + template constexpr auto rbegin(C& c) -> decltype(c.rbegin()); + template constexpr auto rbegin(const C& c) -> decltype(c.rbegin()); + + template constexpr auto rend(C& c) -> decltype(c.rend()); + template constexpr auto rend(const C& c) -> decltype(c.rend()); + + template + constexpr reverse_iterator rbegin(T (&array)[N]); + template + constexpr reverse_iterator rend(T (&array)[N]); + + template + constexpr reverse_iterator rbegin(initializer_list); + template + constexpr reverse_iterator rend(initializer_list); + + template + constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); + template + constexpr auto cend(const C& c) -> decltype(std::rend(c)); +} diff --git a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc index e59d666307d..874f3de1eb8 100644 --- a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc +++ b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc @@ -25,7 +25,7 @@ #include -// { dg-error "multiple inlined namespaces" "" { target *-*-* } 324 } +// { dg-error "multiple inlined namespaces" "" { target *-*-* } 332 } // "template argument 1 is invalid" // { dg-prune-output "tuple:993" } -- 2.30.2