Skip to content

Commit 5a5d2f4

Browse files
committed
[libc++] Fix constant initialization of unique_ptr in C++17 and prior
1 parent a974667 commit 5a5d2f4

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

libcxx/include/__memory/compressed_pair.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ template <class _ToPad,
5656
bool _Empty = ((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) ||
5757
is_reference<_ToPad>::value || sizeof(_ToPad) == __datasizeof_v<_ToPad>)>
5858
class __compressed_pair_padding {
59-
char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>];
59+
char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {};
6060
};
6161

6262
template <class _ToPad>

libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main(int, char**)
3232
struct TestConstexpr : public std::any {
3333
constexpr TestConstexpr() : std::any() {}
3434
};
35-
static TEST_CONSTINIT std::any a;
35+
TEST_CONSTINIT static std::any a;
3636
(void)a;
3737
}
3838
{

libcxx/test/support/test_macros.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@
221221
#endif
222222

223223
#if TEST_STD_VER > 17
224-
#define TEST_CONSTINIT constinit
224+
# define TEST_CONSTINIT constinit
225+
#elif __has_cpp_attribute(clang::require_constant_initialization)
226+
# define TEST_CONSTINIT [[clang::require_constant_initialization]]
225227
#else
226-
#define TEST_CONSTINIT
228+
# define TEST_CONSTINIT
227229
#endif
228230

229231
#if TEST_STD_VER < 11

0 commit comments

Comments
 (0)