[libcxx-commits] [libcxx] [libc++] Fix constant initialization of unique_ptr in C++17 and prior (PR #108956)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 17 03:52:21 PDT 2024


https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/108956

>From f7885f02cc98726b21536af2cc176da9715c9053 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 17 Sep 2024 12:50:01 +0200
Subject: [PATCH] [libc++] Fix constant initialization of unique_ptr in C++17
 and prior

---
 libcxx/include/__memory/compressed_pair.h | 2 +-
 libcxx/test/support/test_macros.h         | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h
index 629e3ad8848ffa..afa78f99612693 100644
--- a/libcxx/include/__memory/compressed_pair.h
+++ b/libcxx/include/__memory/compressed_pair.h
@@ -56,7 +56,7 @@ template <class _ToPad>
 class __compressed_pair_padding {
   char __padding_[((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || is_reference<_ToPad>::value)
                       ? 0
-                      : sizeof(_ToPad) - __datasizeof_v<_ToPad>];
+                      : sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {};
 };
 
 #  define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2)                                                  \
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index 3aa818af1d2695..ae171b3f223ab3 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -221,9 +221,11 @@
 #endif
 
 #if TEST_STD_VER > 17
-#define TEST_CONSTINIT constinit
+#  define TEST_CONSTINIT constinit
+#elif __has_cpp_attribute(clang::require_constant_initialization)
+#  define TEST_CONSTINIT [[clang::require_constant_initialization]]
 #else
-#define TEST_CONSTINIT
+#  define TEST_CONSTINIT
 #endif
 
 #if TEST_STD_VER < 11



More information about the libcxx-commits mailing list