Skip to content

Commit

Permalink
[libc++] Fix constant initialization of unique_ptr in C++17 and prior
Browse files Browse the repository at this point in the history
  • Loading branch information
philnik777 committed Sep 17, 2024
1 parent 50320ec commit 1ce42ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libcxx/include/__memory/compressed_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03

// <memory>

// Check that uniuqe_ptr<T> is constant initialized

#include <memory>

#include "test_macros.h"

TEST_CONSTINIT std::unique_ptr<int> ptr;
6 changes: 4 additions & 2 deletions libcxx/test/support/test_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1ce42ba

Please sign in to comment.