[libcxx-commits] [PATCH] D101206: [libc++] Remove UB in std::list

Amy Huang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 26 10:33:08 PDT 2021


akhuang updated this revision to Diff 340581.
akhuang added a comment.

Remove fix for c++03.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101206/new/

https://reviews.llvm.org/D101206

Files:
  libcxx/include/list


Index: libcxx/include/list
===================================================================
--- libcxx/include/list
+++ libcxx/include/list
@@ -270,11 +270,20 @@
 struct __list_node
     : public __list_node_base<_Tp, _VoidPtr>
 {
+#ifndef _LIBCPP_CXX03_LANG
+  union { _Tp __value_; };
+#else
     _Tp __value_;
+#endif
 
     typedef __list_node_base<_Tp, _VoidPtr> __base;
     typedef typename __base::__link_pointer __link_pointer;
 
+#ifndef _LIBCPP_CXX03_LANG
+    _LIBCPP_INLINE_VISIBILITY
+    __list_node() {}
+#endif
+
     _LIBCPP_INLINE_VISIBILITY
     __link_pointer __as_link() {
         return static_cast<__link_pointer>(__base::__self());
@@ -1113,6 +1122,9 @@
     _LIBCPP_INLINE_VISIBILITY
     __hold_pointer __allocate_node(__node_allocator& __na) {
       __node_pointer __p = __node_alloc_traits::allocate(__na, 1);
+#ifndef _LIBCPP_CXX03_LANG
+      ::new ((void*)_VSTD::addressof(*__p)) __node();
+#endif
       __p->__prev_ = nullptr;
       return __hold_pointer(__p, __node_destructor(__na, 1));
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101206.340581.patch
Type: text/x-patch
Size: 1036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210426/cb7cf262/attachment.bin>


More information about the libcxx-commits mailing list