[libcxx-commits] [libcxx] [libc++] Backport implementation of LWG2187 (PR #222006)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 8 06:59:01 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

<details>
<summary>Changes</summary>

libc++ has LWG2187 implemented in 2d6e2834a8abcce862ef17c44f62e4de41662748 but only since C++14 mode. Usually, resolution of an LWG issue should be treated as a Defect Report and applied to old modes. In the case of LWG2187, the resolution should be applied to C++11.

Additionally, this patch makes `vector<bool, A>`'s `emplace` and `emplace_back` also available in C++03 mode (using non-frozen headers), because we have been doing so for the primary `vector` template.

---
Full diff: https://github.com/llvm/llvm-project/pull/222006.diff


4 Files Affected:

- (modified) libcxx/include/__vector/vector_bool.h (+6-9) 
- (modified) libcxx/include/vector (+2-2) 
- (modified) libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp (+2-1) 
- (modified) libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp (+2-1) 


``````````diff
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 6269ec287f7f9..0c7f514b4d9d7 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -322,20 +322,19 @@ class _LIBCPP_WARN_UNUSED vector<bool, _Allocator> {
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
-#if _LIBCPP_STD_VER >= 14
+
   template <class... _Args>
-#  if _LIBCPP_STD_VER >= 17
+#if _LIBCPP_STD_VER >= 17
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
-#  else
+#else
   _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args)
-#  endif
+#endif
   {
     push_back(value_type(std::forward<_Args>(__args)...));
-#  if _LIBCPP_STD_VER >= 17
+#if _LIBCPP_STD_VER >= 17
     return this->back();
-#  endif
-  }
 #endif
+  }
 
 #if _LIBCPP_STD_VER >= 23
   template <_ContainerCompatibleRange<bool> _Range>
@@ -349,12 +348,10 @@ class _LIBCPP_WARN_UNUSED vector<bool, _Allocator> {
     --__size_;
   }
 
-#if _LIBCPP_STD_VER >= 14
   template <class... _Args>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) {
     return insert(__position, value_type(std::forward<_Args>(__args)...));
   }
-#endif
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
diff --git a/libcxx/include/vector b/libcxx/include/vector
index 0fb45f67be5f2..271ec9976d733 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -230,12 +230,12 @@ public:
     const_reference back() const;
 
     void push_back(const value_type& x);
-    template <class... Args> reference emplace_back(Args&&... args);  // C++14; reference in C++17
+    template <class... Args> reference emplace_back(Args&&... args);  // returns void/reference until/since C++17
     template<container-compatible-range<T> R>
       constexpr void append_range(R&& rg); // C++23
     void pop_back();
 
-    template <class... Args> iterator emplace(const_iterator position, Args&&... args);  // C++14
+    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
     iterator insert(const_iterator position, const value_type& x);
     iterator insert(const_iterator position, size_type n, const value_type& x);
     template <class InputIterator>
diff --git a/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp
index 810a1968605d8..0f6c1cef4d13e 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp
@@ -6,7 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03, c++11
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
 // <vector>
 //  vector<bool>
 
diff --git a/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp
index 87da6fd9f6019..783789a78c018 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp
@@ -6,7 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03, c++11
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
 // <vector>
 //  vector.bool
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/222006


More information about the libcxx-commits mailing list