Skip to content

Commit

Permalink
[libc++][format] Implement LWG4061
Browse files Browse the repository at this point in the history
Effectively reverts commit 36ce0c3.
  • Loading branch information
frederick-vs-ja committed Jul 1, 2024
1 parent 8598bcb commit 857a9ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions libcxx/include/__format/format_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class
_LIBCPP_HIDE_FROM_ABI explicit basic_format_context(_OutIt __out_it, basic_format_args<basic_format_context> __args)
: __out_it_(std::move(__out_it)), __args_(__args) {}
# endif

basic_format_context(const basic_format_context&) = delete;
basic_format_context& operator=(const basic_format_context&) = delete;
};

// A specialization for __retarget_buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,27 @@ void test() {
#endif
}

// The default constructor is suppressed by the deleted copy operations.
// The move operations are implicitly deleted due to the deleted copy operations.

// std::back_insert_iterator<std::string>, copyable
static_assert(std::is_copy_constructible_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
static_assert(std::is_copy_assignable_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
static_assert(
!std::is_default_constructible_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);

static_assert(!std::is_copy_constructible_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
static_assert(!std::is_copy_assignable_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);

static_assert(std::is_move_constructible_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
static_assert(std::is_move_assignable_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
static_assert(!std::is_move_constructible_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
static_assert(!std::is_move_assignable_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);

// cpp20_output_iterator, move only
static_assert(!std::is_default_constructible_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);

static_assert(!std::is_copy_constructible_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
static_assert(!std::is_copy_assignable_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);

static_assert(std::is_move_constructible_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
static_assert(std::is_move_assignable_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
static_assert(!std::is_move_constructible_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
static_assert(!std::is_move_assignable_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);

int main(int, char**) {
test<std::back_insert_iterator<std::basic_string<char>>, char>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct X : std::variant<X*> {

template <>
struct std::formatter<X, char> : std::formatter<std::string, char> {
static constexpr auto format(const X& x, auto ctx) {
static constexpr auto format(const X& x, auto& ctx) {
if (!x.p)
return ctx.out();
auto m = [&](const X* t) { return std::format_to(ctx.out(), "{}", *t); };
Expand Down

0 comments on commit 857a9ef

Please sign in to comment.