[libcxx-commits] [PATCH] D126210: [libcxx] Fix allocator<void>::pointer in C++20 with removed members

Ilya Biryukov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 23 08:09:38 PDT 2022


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: ldionne.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

This only changes behavior in
`-D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS` mode.

Uses of `allocator<void>::pointer` resulted in compiler errors after D104323 <https://reviews.llvm.org/D104323>.
If we instantiate the primary template, `allocator<void>::reference` produces
an error 'cannot form references to void'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126210

Files:
  libcxx/include/__memory/allocator.h
  libcxx/test/std/utilities/memory/default.allocator/allocator_types.void.compile.cxx20_with_removed_members.pass.cpp


Index: libcxx/test/std/utilities/memory/default.allocator/allocator_types.void.compile.cxx20_with_removed_members.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/utilities/memory/default.allocator/allocator_types.void.compile.cxx20_with_removed_members.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Check that the nested types of std::allocator<void> are provided in C++20
+// with a flag that keeps the removed members.
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
+
+#include <memory>
+#include <type_traits>
+
+int main() {
+  static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), "");
+  static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), "");
+  static_assert((std::is_same<std::allocator<void>::value_type, void>::value), "");
+  static_assert((std::is_same<std::allocator<void>::rebind<int>::other, std::allocator<int> >::value), "");
+}
Index: libcxx/include/__memory/allocator.h
===================================================================
--- libcxx/include/__memory/allocator.h
+++ libcxx/include/__memory/allocator.h
@@ -27,7 +27,7 @@
 
 template <class _Tp> class allocator;
 
-#if _LIBCPP_STD_VER <= 17
+#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
 template <>
 class _LIBCPP_TEMPLATE_VIS allocator<void>
 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126210.431381.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220523/c4742e53/attachment.bin>


More information about the libcxx-commits mailing list