diff --git a/libcxx/TODO.TXT b/libcxx/TODO.TXT --- a/libcxx/TODO.TXT +++ b/libcxx/TODO.TXT @@ -21,4 +21,3 @@ * Find all sequences of >2 underscores and eradicate them. * run clang-tidy on libc++ * Document the "conditionally-supported" bits of libc++ -* Put a static_assert in std::allocator to deny const/volatile types (LWG 2447) diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h --- a/libcxx/include/__memory/allocator.h +++ b/libcxx/include/__memory/allocator.h @@ -80,6 +80,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::value, allocator<_Tp> > { + static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); public: typedef size_t size_type; typedef ptrdiff_t difference_type; @@ -162,6 +163,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::value, allocator > { + static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); public: typedef size_t size_type; typedef ptrdiff_t difference_type; diff --git a/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp b/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libc++ + +// http://wg21.link/LWG2447 gives implementors freedom to reject volatile types in `std::allocator`. + +#include + +std::allocator A1; // expected-error@*:* {{std::allocator does not support volatile types}} +std::allocator A2; // expected-error@*:* {{std::allocator does not support volatile types}} diff --git a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp --- a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp +++ b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp @@ -204,8 +204,6 @@ test_true >(); #ifdef _LIBCPP_VERSION test_true >(); - test_true >(); - test_true >(); #endif // _LIBCPP_VERSION test_true >(); test_true >(); @@ -227,8 +225,6 @@ test_true >(); #ifdef _LIBCPP_VERSION test_true >(); - test_true >(); - test_true >(); #endif // _LIBCPP_VERSION test_true >(); test_true >(); diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -73,6 +73,26 @@ void test_pointer_to_function() {} #endif // _LIBCPP_VERSION +template +void test(const T &t0) +{ + { + T t1 = t0; + std::shared_ptr p0 = std::make_shared(t0); + std::shared_ptr p1 = std::make_shared(t1); + assert(*p0 == t0); + assert(*p1 == t1); + } + + { + const T t1 = t0; + std::shared_ptr p0 = std::make_shared(t0); + std::shared_ptr p1 = std::make_shared(t1); + assert(*p0 == t0); + assert(*p1 == t1); + } +} + int main(int, char**) { int nc = globalMemCounter.outstanding_new; @@ -108,5 +128,9 @@ #endif assert(A::count == 0); + test(true); + test(3); + test(5.0); + return 0; } diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.volatile.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.volatile.pass.cpp deleted file mode 100644 --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.volatile.pass.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// shared_ptr - -// template shared_ptr make_shared(Args&&... args); - -#include -#include - -#include "test_macros.h" - -template -void test(const T &t0) -{ - { - T t1 = t0; - std::shared_ptr p0 = std::make_shared(t0); - std::shared_ptr p1 = std::make_shared(t1); - assert(*p0 == t0); - assert(*p1 == t1); - } - - { - const T t1 = t0; - std::shared_ptr p0 = std::make_shared(t0); - std::shared_ptr p1 = std::make_shared(t1); - assert(*p0 == t0); - assert(*p1 == t1); - } - - { - volatile T t1 = t0; - std::shared_ptr p0 = std::make_shared(t0); - std::shared_ptr p1 = std::make_shared(t1); - assert(*p0 == t0); - assert(*p1 == t1); - } - - { - const volatile T t1 = t0; - std::shared_ptr p0 = std::make_shared(t0); - std::shared_ptr p1 = std::make_shared(t1); - assert(*p0 == t0); - assert(*p1 == t1); - } - -} - -int main(int, char**) -{ - test(true); - test(3); - test(5.0); - - return 0; -}