Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 58 additions & 56 deletions stl/inc/memory

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
// P2136R3 invoke_r()
// P2166R1 Prohibiting basic_string And basic_string_view Construction From nullptr
// P2186R2 Removing Garbage Collection Support
// P2273R3 constexpr unique_ptr
// P2443R1 views::chunk_by

// Parallel Algorithms Notes
Expand Down Expand Up @@ -633,6 +634,13 @@
#define _CONSTEXPR20 inline
#endif // ^^^ inline (not constexpr) in C++17 and earlier ^^^

// Functions that became constexpr in C++23
#if _HAS_CXX23
#define _CONSTEXPR23 constexpr
#else // ^^^ constexpr in C++23 and later / inline (not constexpr) in C++20 and earlier vvv
#define _CONSTEXPR23 inline
#endif // ^^^ inline (not constexpr) in C++20 and earlier ^^^

// P0607R0 Inline Variables For The STL
#if _HAS_CXX17
#define _INLINE_VAR inline
Expand Down Expand Up @@ -1286,7 +1294,6 @@
#define __cpp_lib_constexpr_dynamic_alloc 201907L
#define __cpp_lib_constexpr_functional 201907L
#define __cpp_lib_constexpr_iterator 201811L
#define __cpp_lib_constexpr_memory 201811L
#define __cpp_lib_constexpr_numeric 201911L
#define __cpp_lib_constexpr_string 201907L
#define __cpp_lib_constexpr_string_view 201811L
Expand Down Expand Up @@ -1398,6 +1405,12 @@
#define __cpp_lib_chrono 201510L // P0092R1 <chrono> floor(), ceil(), round(), abs()
#endif // _HAS_CXX17

#if _HAS_CXX23
#define __cpp_lib_constexpr_memory 202202L // P2273R3 constexpr unique_ptr
#elif _HAS_CXX20
#define __cpp_lib_constexpr_memory 201811L // P1006R1 constexpr For pointer_traits<T*>::pointer_to()
#endif // _HAS_CXX20

#ifndef _M_CEE
#if _HAS_CXX20
#define __cpp_lib_execution 201902L // P1001R2 execution::unseq
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ tests\P1951R1_default_arguments_pair_forward_ctor
tests\P2136R3_invoke_r
tests\P2162R2_std_visit_for_derived_classes_from_variant
tests\P2231R1_complete_constexpr_optional_variant
tests\P2273R3_constexpr_unique_ptr
tests\P2401R0_conditional_noexcept_for_exchange
tests\P2415R2_owning_view
tests\P2443R1_views_chunk_by
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P2273R3_constexpr_unique_ptr/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_latest_matrix.lst
131 changes: 131 additions & 0 deletions tests/std/tests/P2273R3_constexpr_unique_ptr/test.compile.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <memory>
#include <utility>

using namespace std;

struct Dummy {
constexpr int test() const {
return 10;
}
};

constexpr bool test() {
// [memory.syn]
{
auto p1 = make_unique<int>(42);
auto p2 = make_unique_for_overwrite<int>();
swap(p1, p2);
assert(p1 == p1);
assert(p1 != p2);

#if defined(__EDG__) || defined(__clang__) // TRANSITION, DevCom-1436243
auto p3 = make_unique<int[]>(10);
auto p4 = make_unique_for_overwrite<int[]>(4);
swap(p3, p4);
assert(p3 == p3);
assert(p3 != p4);
#endif // defined(__EDG__) || defined(__clang__)

auto p5 = unique_ptr<int>{nullptr};
assert(p5 == nullptr);
assert(nullptr == p5);
assert(!(p5 != nullptr));
assert(!(nullptr != p5));
#ifndef __EDG__ // TRANSITION, DevCom-1670927
assert(!(p5 < nullptr));
assert(!(nullptr < p5));
assert(p5 <= nullptr);
assert(nullptr <= p5);
assert(!(p5 > nullptr));
assert(!(nullptr > p5));
assert(p5 >= nullptr);
assert(nullptr >= p5);
assert((p5 <=> nullptr) == strong_ordering::equal);
assert((nullptr <=> p5) == strong_ordering::equal);
#endif // !__EDG__
}

// changes in [unique.ptr.dltr.dflt] and [unique.ptr.dltr.dflt1]
// will be tested via destructors and copy assign/constructors

// [unique.ptr.single.general]
{
// constructors
auto p1 = unique_ptr<int>{new int{}};
auto d1 = default_delete<int>{};
auto p2 = unique_ptr<int>{new int{}, d1};
auto p3 = unique_ptr<int>{new int{}, default_delete<int>{}};
auto p4 = move(p3);
auto p5 = unique_ptr<int>{nullptr};
auto p6 = unique_ptr<int, default_delete<int>&>{new int{}, d1};
auto p7 = unique_ptr<int>{move(p6)};

// assignment
p3 = move(p4);
auto p8 = unique_ptr<int, default_delete<int>&>{new int{}, d1};
p7 = move(p8);
p1 = nullptr;

// observers
assert(*p2 == 0);
auto p9 = unique_ptr<Dummy>{new Dummy};
assert(p9->test() == 10);
assert(p2.get() != nullptr);
[[maybe_unused]] auto& d2 = p2.get_deleter();
[[maybe_unused]] auto& d3 = as_const(p2).get_deleter();
auto b1 = static_cast<bool>(p2);
assert(b1);

// modifiers
p1.reset();
p1.reset(new int{});
auto manual_delete = p2.release();
delete manual_delete;
p5.swap(p1);
}

// [unique.ptr.runtime.general]
{
// constructors
auto p1 = unique_ptr<int[]>{new int[5]};
auto d1 = default_delete<int[]>{};
auto p2 = unique_ptr<int[]>{new int[5], d1};
auto p3 = unique_ptr<int[]>{new int[5], default_delete<int[]>{}};
auto p4 = move(p1);
auto p5 = unique_ptr<int[], default_delete<int[]>&>{new int[5], d1};
auto p6 = unique_ptr<int[]>{move(p5)};

// assignment
p1 = move(p4);
auto p7 = unique_ptr<int[], default_delete<int[]>&>{new int[5], d1};
p6 = move(p7);
p4 = nullptr;

// observers
p1[0] = 50;
assert(p1[0] == 50);
assert(p1.get() != nullptr);
[[maybe_unused]] auto& d2 = p1.get_deleter();
[[maybe_unused]] auto& d3 = as_const(p1).get_deleter();
auto b1 = static_cast<bool>(p1);
assert(b1);

// modifiers
auto manual_delete = p1.release();
delete[] manual_delete;
p1.reset(new int[3]);
p1.reset(nullptr);
p1.reset();
p1.swap(p4);
}

return true;
}

static_assert(test());

int main() {} // COMPILE-ONLY
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ void memory_test() {
};
my_shared_from_this msft{};
default_delete<void> dd0{default_delete<int>{}};
(void) dd0;
default_delete<int[]> dd1{default_delete<int[]>{}};
dd1(new int[5]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,15 @@ STATIC_ASSERT(__cpp_lib_constexpr_iterator == 201811L);
#endif
#endif

#if _HAS_CXX20
#if _HAS_CXX23
#ifndef __cpp_lib_constexpr_memory
#error __cpp_lib_constexpr_memory is not defined
#elif __cpp_lib_constexpr_memory != 202202L
#error __cpp_lib_constexpr_memory is not 202202L
#else
STATIC_ASSERT(__cpp_lib_constexpr_memory == 202202L);
#endif
#elif _HAS_CXX20
#ifndef __cpp_lib_constexpr_memory
#error __cpp_lib_constexpr_memory is not defined
#elif __cpp_lib_constexpr_memory != 201811L
Expand Down
1 change: 1 addition & 0 deletions tests/tr1/tests/memory3/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void t_del() { // test default_delete for scalars

STD default_delete<derived> del1;
STD default_delete<base> del2(del1);
(void) del2;
}

void t_del_arr() { // test default_delete for arrays
Expand Down