diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -2178,6 +2178,9 @@ }; #endif +// Tag used to default initialize one or both of the pair's elements. +struct __default_init_tag {}; + template ::value && !__libcpp_is_final<_Tp>::value> @@ -2188,6 +2191,8 @@ #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {} + _LIBCPP_INLINE_VISIBILITY constexpr + __compressed_pair_elem(__default_init_tag) {} template ::type>::value @@ -2207,6 +2212,8 @@ #else _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {} _LIBCPP_INLINE_VISIBILITY + __compressed_pair_elem(__default_init_tag) {} + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {} #endif diff --git a/libcxx/test/std/memory/compressed_pair/compressed_pair.pass.cpp b/libcxx/test/std/memory/compressed_pair/compressed_pair.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/memory/compressed_pair/compressed_pair.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include "test_macros.h" + +typedef std::__compressed_pair IntPair; + +void test_constructor() { + IntPair value; + assert(value.first() == 0); + assert(value.second() == 0); + + value.first() = 1; + value.second() = 2; + new (&value) IntPair; + assert(value.first() == 0); + assert(value.second() == 0); +} + +void test_constructor_default_init() { + IntPair value; + value.first() = 1; + value.second() = 2; + + new (&value) IntPair(std::__default_init_tag(), 3); + assert(value.first() == 1); + assert(value.second() == 3); + + new (&value) IntPair(4, std::__default_init_tag()); + assert(value.first() == 4); + assert(value.second() == 3); + + new (&value) IntPair(std::__default_init_tag(), std::__default_init_tag()); + assert(value.first() == 4); + assert(value.second() == 3); +} + +int main(int, char**) +{ + test_constructor(); + test_constructor_default_init(); + return 0; +} diff --git a/libcxx/test/std/memory/nothing_to_do.pass.cpp b/libcxx/test/std/memory/nothing_to_do.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/memory/nothing_to_do.pass.cpp @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +int main(int, char**) +{ + + return 0; +}