From e0742c4abf1a3c4aa23586233df895fe8fbcbb00 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 20 Mar 2018 23:02:53 +0000 Subject: [PATCH] Implement LWG3035: std::allocator's constructors should be constexpr. llvm-svn: 328059 --- libcxx/include/memory | 25 ++++++++--- .../default.allocator/allocator.ctor.pass.cpp | 50 ++++++++++++++++++++++ 2 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp diff --git a/libcxx/include/memory b/libcxx/include/memory index bc5c4c6..ea52ba2 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -126,9 +126,10 @@ public: template struct rebind {typedef allocator other;}; - allocator() noexcept; - allocator(const allocator&) noexcept; - template allocator(const allocator&) noexcept; + constexpr allocator() noexcept; // constexpr in C++20 + constexpr allocator(const allocator&) noexcept; // constexpr in C++20 + template + constexpr allocator(const allocator&) noexcept; // constexpr in C++20 ~allocator(); pointer address(reference x) const noexcept; const_pointer address(const_reference x) const noexcept; @@ -1778,8 +1779,13 @@ public: template struct rebind {typedef allocator<_Up> other;}; - _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {} - template _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator() _NOEXCEPT {} + + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator(const allocator<_Up>&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT @@ -1877,8 +1883,13 @@ public: template struct rebind {typedef allocator<_Up> other;}; - _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {} - template _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator() _NOEXCEPT {} + + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 + allocator(const allocator<_Up>&) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator::const_pointer = 0) diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp new file mode 100644 index 0000000..3841cb53 --- /dev/null +++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// +// template +// class allocator +// { +// public: // All of these are constexpr after C++17 +// constexpr allocator() noexcept; +// constexpr allocator(const allocator&) noexcept; +// template constexpr allocator(const allocator&) noexcept; +// ... +// }; + +#include +#include + +#include "test_macros.h" + + +int main() +{ + { + typedef std::allocator AC; + typedef std::allocator AL; + + constexpr AC a1; + constexpr AC a2{a1}; + constexpr AL a3{a2}; + (void) a3; + } + { + typedef std::allocator AC; + typedef std::allocator AL; + + constexpr AC a1; + constexpr AC a2{a1}; + constexpr AL a3{a2}; + (void) a3; + } + +} -- 2.7.4