[libcxx-commits] [libcxx] [libc++][C++26] P2562R1: `constexpr` Stable Sorting (PR #110320)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 3 04:13:42 PST 2024


================
@@ -34,6 +34,16 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+// Workaround for "constexpr placement new" bug in gcc (fixed in 14.2).
+// See https://github.com/llvm/llvm-project/pull/110320#discussion_r1788557715.
+#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 <= 140100)
+#  define _LIBCPP_MOVING_PLACEMENT_NEW(__ptr, __type, __move_func, __iter)                                             \
+    [__ptr, &__iter] { ::new ((void*)__ptr) __type(__move_func(__iter)); }()
+#else
+#  define _LIBCPP_MOVING_PLACEMENT_NEW(__ptr, __type, __move_func, __iter)                                             \
+    ::new ((void*)__ptr) __type(__move_func(__iter))
+#endif
----------------
frederick-vs-ja wrote:

> Why don't we simply use `construct_at`?

I'm afraid that using `construct_at` possibly breaks guaranteed copy elision in some rare cases.

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


More information about the libcxx-commits mailing list