Skip to content
Merged
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
57 changes: 40 additions & 17 deletions tests/std/tests/GH_005504_avoid_function_call_wrapping/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,23 @@ void test_plain_call(const int expected_copies) {
}

template <class OuterWrapper, class InnerWrapper, class Callable>
void test_wrapped_call(const int expected_copies) {
void test_wrapped_move_call(const int expected_copies) {
InnerWrapper inner{Callable{}};
OuterWrapper outer{move(inner)};
assert(!inner);
assert(outer(copy_counter{}) == expected_copies);
}

template <class OuterWrapper, class MiddleWrapper, class InnerWrapper, class Callable>
void test_wrapped_move_move_call(const int expected_copies) {
InnerWrapper inner{Callable{}};
MiddleWrapper middle{move(inner)};
OuterWrapper outer{move(middle)};
assert(!inner);
assert(!middle);
assert(outer(copy_counter{}) == expected_copies);
}

template <class OuterWrapper, class InnerWrapper, class Callable>
void test_wrapped_copy_call(const int expected_copies) {
InnerWrapper inner{Callable{}};
Expand Down Expand Up @@ -155,25 +165,33 @@ int main() {
alloc_checker{1}, test_plain_call<move_only_function<fn_type>, large_callable>(0);

// Moves to the same
alloc_checker{0}, test_wrapped_call<function<fn_type>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<function<fn_type>, function<fn_type>, large_callable>(0);
alloc_checker{0}, test_wrapped_move_call<function<fn_type>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_move_call<function<fn_type>, function<fn_type>, large_callable>(0);
alloc_checker{0}, test_wrapped_copy_call<function<fn_type>, function<fn_type>, small_callable>(0);
alloc_checker{2}, test_wrapped_copy_call<function<fn_type>, function<fn_type>, large_callable>(0);
alloc_checker{0}, test_wrapped_call<move_only_function<fn_type>, move_only_function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<move_only_function<fn_type>, move_only_function<fn_type>, large_callable>(0);
alloc_checker{0},
test_wrapped_move_call<move_only_function<fn_type>, move_only_function<fn_type>, small_callable>(0);
alloc_checker{1},
test_wrapped_move_call<move_only_function<fn_type>, move_only_function<fn_type>, large_callable>(0);

// Abominables and noexcept specifier
alloc_checker{0}, test_wrapped_call<move_only_function<fn_type_r>, move_only_function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<move_only_function<fn_type_r>, move_only_function<fn_type>, large_callable>(0);
alloc_checker{0}, test_wrapped_call<move_only_function<fn_type>, move_only_function<fn_type_c>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<move_only_function<fn_type>, move_only_function<fn_type_c>, large_callable>(0);
alloc_checker{0},
test_wrapped_move_call<move_only_function<fn_type_r>, move_only_function<fn_type>, small_callable>(0);
alloc_checker{1},
test_wrapped_move_call<move_only_function<fn_type_r>, move_only_function<fn_type>, large_callable>(0);
alloc_checker{0},
test_wrapped_move_call<move_only_function<fn_type>, move_only_function<fn_type_c>, small_callable>(0);
alloc_checker{1},
test_wrapped_move_call<move_only_function<fn_type>, move_only_function<fn_type_c>, large_callable>(0);

static_assert(!is_constructible_v<move_only_function<fn_type>, move_only_function<fn_type_r>>);
static_assert(!is_constructible_v<move_only_function<fn_type_c>, move_only_function<fn_type>>);

#ifdef __cpp_noexcept_function_type
alloc_checker{0}, test_wrapped_call<move_only_function<fn_type>, move_only_function<fn_type_nx>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<move_only_function<fn_type>, move_only_function<fn_type_nx>, large_callable>(0);
alloc_checker{0},
test_wrapped_move_call<move_only_function<fn_type>, move_only_function<fn_type_nx>, small_callable>(0);
alloc_checker{1},
test_wrapped_move_call<move_only_function<fn_type>, move_only_function<fn_type_nx>, large_callable>(0);

static_assert(!is_constructible_v<move_only_function<fn_type_nx>, move_only_function<fn_type>>);
#endif // defined(__cpp_noexcept_function_type)
Expand All @@ -182,16 +200,21 @@ int main() {

// Moves from function to move_only_function
alloc_checker{is_64_bit ? 0 : 1},
test_wrapped_call<move_only_function<fn_type>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<move_only_function<fn_type>, function<fn_type>, large_callable>(0);
test_wrapped_move_call<move_only_function<fn_type>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_move_call<move_only_function<fn_type>, function<fn_type>, large_callable>(0);

alloc_checker{is_64_bit ? 0 : 1}, test_wrapped_move_move_call<move_only_function<fn_type>,
move_only_function<fn_type>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_move_move_call<move_only_function<fn_type>, move_only_function<fn_type>,
function<fn_type>, large_callable>(0);
Comment on lines +206 to +209

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are the essential missed coverage being added.

The rest of the change is the renaming.


// Moves from function to abominable move_only_function
alloc_checker{is_64_bit ? 0 : 1},
test_wrapped_call<move_only_function<fn_type_r>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<move_only_function<fn_type_r>, function<fn_type>, large_callable>(0);
test_wrapped_move_call<move_only_function<fn_type_r>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_move_call<move_only_function<fn_type_r>, function<fn_type>, large_callable>(0);
alloc_checker{is_64_bit ? 0 : 1},
test_wrapped_call<move_only_function<fn_type_c>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_call<move_only_function<fn_type_c>, function<fn_type>, large_callable>(0);
test_wrapped_move_call<move_only_function<fn_type_c>, function<fn_type>, small_callable>(0);
alloc_checker{1}, test_wrapped_move_call<move_only_function<fn_type_c>, function<fn_type>, large_callable>(0);

#ifdef __cpp_noexcept_function_type
static_assert(!is_constructible_v<move_only_function<fn_type_nx>, function<fn_type>>);
Expand Down