From 3be9ded290ac5232d52a8353235ff7d08ce02fae Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 18 Jun 2018 16:47:07 +0100 Subject: [PATCH] LWG 3035. std::allocator's constructors should be constexpr LWG 3035. std::allocator's constructors should be constexpr * include/bits/allocator.h (allocator): Add constexpr to constructors for C++2a. Replace dynamic exception specifications with NOTHROW macro. (allocator, operator==, operator!=): Replace USE_NOEXCEPT macro with NOTHROW. * include/bits/c++config (_GLIBCXX20_CONSTEXPR): Define. * include/ext/malloc_allocator.h (malloc_allocator): Add constexpr to constructors for C++2a. * include/ext/new_allocator.h (new_allocator): Likewise. From-SVN: r261703 --- libstdc++-v3/ChangeLog | 13 ++++++++++++ libstdc++-v3/include/bits/allocator.h | 22 +++++++++++++-------- libstdc++-v3/include/bits/c++config | 12 +++++++++-- libstdc++-v3/include/ext/malloc_allocator.h | 3 +++ libstdc++-v3/include/ext/new_allocator.h | 3 +++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2c3237a2ed2..166522ccedf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2018-06-18 Jonathan Wakely + + LWG 3035. std::allocator's constructors should be constexpr + * include/bits/allocator.h (allocator): Add constexpr to constructors + for C++2a. Replace dynamic exception specifications with NOTHROW + macro. + (allocator, operator==, operator!=): Replace USE_NOEXCEPT macro with + NOTHROW. + * include/bits/c++config (_GLIBCXX20_CONSTEXPR): Define. + * include/ext/malloc_allocator.h (malloc_allocator): Add constexpr + to constructors for C++2a. + * include/ext/new_allocator.h (new_allocator): Likewise. + 2018-06-16 Jonathan Wakely LWG 3076 basic_string CTAD ambiguity diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 2da499f1498..c4e3a4b9c15 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -128,19 +128,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef true_type is_always_equal; #endif - allocator() throw() { } + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3035. std::allocator's constructors should be constexpr + _GLIBCXX20_CONSTEXPR + allocator() _GLIBCXX_NOTHROW { } - allocator(const allocator& __a) throw() + _GLIBCXX20_CONSTEXPR + allocator(const allocator& __a) _GLIBCXX_NOTHROW : __allocator_base<_Tp>(__a) { } + #if __cplusplus >= 201103L // Avoid implicit deprecation. allocator& operator=(const allocator&) = default; #endif template - allocator(const allocator<_Tp1>&) throw() { } + _GLIBCXX20_CONSTEXPR + allocator(const allocator<_Tp1>&) _GLIBCXX_NOTHROW { } - ~allocator() throw() { } + ~allocator() _GLIBCXX_NOTHROW { } // Inherit everything else. }; @@ -148,25 +154,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline bool operator==(const allocator<_T1>&, const allocator<_T2>&) - _GLIBCXX_USE_NOEXCEPT + _GLIBCXX_NOTHROW { return true; } template inline bool operator==(const allocator<_Tp>&, const allocator<_Tp>&) - _GLIBCXX_USE_NOEXCEPT + _GLIBCXX_NOTHROW { return true; } template inline bool operator!=(const allocator<_T1>&, const allocator<_T2>&) - _GLIBCXX_USE_NOEXCEPT + _GLIBCXX_NOTHROW { return false; } template inline bool operator!=(const allocator<_Tp>&, const allocator<_Tp>&) - _GLIBCXX_USE_NOEXCEPT + _GLIBCXX_NOTHROW { return false; } // Invalid allocator partial specializations. diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 838afc59dfb..4a096a198db 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -122,15 +122,23 @@ #endif #ifndef _GLIBCXX17_CONSTEXPR -# if __cplusplus > 201402L +# if __cplusplus >= 201703L # define _GLIBCXX17_CONSTEXPR constexpr # else # define _GLIBCXX17_CONSTEXPR # endif #endif +#ifndef _GLIBCXX20_CONSTEXPR +# if __cplusplus > 201703L +# define _GLIBCXX20_CONSTEXPR constexpr +# else +# define _GLIBCXX20_CONSTEXPR +# endif +#endif + #ifndef _GLIBCXX17_INLINE -# if __cplusplus > 201402L +# if __cplusplus >= 201703L # define _GLIBCXX17_INLINE inline # else # define _GLIBCXX17_INLINE diff --git a/libstdc++-v3/include/ext/malloc_allocator.h b/libstdc++-v3/include/ext/malloc_allocator.h index 75a74a39cef..8739c1fdaa3 100644 --- a/libstdc++-v3/include/ext/malloc_allocator.h +++ b/libstdc++-v3/include/ext/malloc_allocator.h @@ -75,11 +75,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef std::true_type propagate_on_container_move_assignment; #endif + _GLIBCXX20_CONSTEXPR malloc_allocator() _GLIBCXX_USE_NOEXCEPT { } + _GLIBCXX20_CONSTEXPR malloc_allocator(const malloc_allocator&) _GLIBCXX_USE_NOEXCEPT { } template + _GLIBCXX20_CONSTEXPR malloc_allocator(const malloc_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { } diff --git a/libstdc++-v3/include/ext/new_allocator.h b/libstdc++-v3/include/ext/new_allocator.h index 78e2019a0b3..19e7ad02e75 100644 --- a/libstdc++-v3/include/ext/new_allocator.h +++ b/libstdc++-v3/include/ext/new_allocator.h @@ -76,11 +76,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef std::true_type propagate_on_container_move_assignment; #endif + _GLIBCXX20_CONSTEXPR new_allocator() _GLIBCXX_USE_NOEXCEPT { } + _GLIBCXX20_CONSTEXPR new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { } template + _GLIBCXX20_CONSTEXPR new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { } ~new_allocator() _GLIBCXX_USE_NOEXCEPT { } -- 2.30.2