[libcxx-commits] [PATCH] D109056: [libc++] Reject volatile types in std::allocator
Joe Loser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 9 07:46:57 PDT 2021
jloser updated this revision to Diff 371595.
jloser retitled this revision from "[libc++][docs] Mark LWG 2447 as incomplete" to "[libc++] Reject volatile types in std::allocator".
jloser edited the summary of this revision.
jloser added a comment.
Add `static_assert` in `std::allocator` to reject cv volatile types.
Add libc++ specific test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109056/new/
https://reviews.llvm.org/D109056
Files:
libcxx/include/__memory/allocator.h
libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
Index: libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++
+
+#include <memory>
+
+auto A1 = std::allocator<volatile int>{}; // expected-error@*:* {{std::allocator does not support volatile types}}
+auto A2 = std::allocator<const volatile int>{}; // expected-error@*:* {{std::allocator does not support volatile types}}
+
+auto A3 = std::allocator<volatile int*>{}; // expected-error@*:* {{std::allocator does not support volatile types}}
+auto A4 = std::allocator<const volatile int*>{}; // expected-error@*:* {{std::allocator does not support volatile types}}
Index: libcxx/include/__memory/allocator.h
===================================================================
--- libcxx/include/__memory/allocator.h
+++ libcxx/include/__memory/allocator.h
@@ -80,6 +80,7 @@
class _LIBCPP_TEMPLATE_VIS allocator
: private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> >
{
+ static_assert(!is_volatile<typename remove_pointer<_Tp>::type>::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<const _Tp>
: private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> >
{
+ static_assert(!is_volatile<typename remove_pointer<_Tp>::type>::value, "std::allocator does not support volatile types");
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109056.371595.patch
Type: text/x-patch
Size: 2022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210909/6eaf2759/attachment.bin>
More information about the libcxx-commits
mailing list