[PATCH] LWG 3035. std::allocator's constructors should be constexpr
Jonathan Wakely
jwakely@redhat.com
Mon Jun 18 15:46:00 GMT 2018
* 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.
Tested powerpc64le-linux, committed to trunk.
-------------- next part --------------
commit 09e0651249e65064ff4fd1181939c4318e64c9eb
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Jun 18 15:41:02 2018 +0100
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.
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<typename _Tp1>
- 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<typename _T1, typename _T2>
inline bool
operator==(const allocator<_T1>&, const allocator<_T2>&)
- _GLIBCXX_USE_NOEXCEPT
+ _GLIBCXX_NOTHROW
{ return true; }
template<typename _Tp>
inline bool
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
- _GLIBCXX_USE_NOEXCEPT
+ _GLIBCXX_NOTHROW
{ return true; }
template<typename _T1, typename _T2>
inline bool
operator!=(const allocator<_T1>&, const allocator<_T2>&)
- _GLIBCXX_USE_NOEXCEPT
+ _GLIBCXX_NOTHROW
{ return false; }
template<typename _Tp>
inline bool
operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
- _GLIBCXX_USE_NOEXCEPT
+ _GLIBCXX_NOTHROW
{ return false; }
// Invalid allocator<cv T> 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<typename _Tp1>
+ _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<typename _Tp1>
+ _GLIBCXX20_CONSTEXPR
new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { }
~new_allocator() _GLIBCXX_USE_NOEXCEPT { }
More information about the Gcc-patches
mailing list