Skip to content

Commit 36ce0c3

Browse files
committed
[libc++][format] Makes format_context copyable.
This was a bug discovered by @jwakely. Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D137911
1 parent 53d234e commit 36ce0c3

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

libcxx/include/__format/format_context.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ class
8585
template <class _Tp>
8686
using formatter_type = formatter<_Tp, _CharT>;
8787

88-
basic_format_context(const basic_format_context&) = delete;
89-
basic_format_context& operator=(const basic_format_context&) = delete;
90-
9188
_LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context>
9289
arg(size_t __id) const noexcept {
9390
return __args_.get(__id);

libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,13 @@
2828

2929
#include "test_basic_format_arg.h"
3030
#include "test_format_context.h"
31+
#include "test_iterators.h"
3132
#include "make_string.h"
3233
#include "platform_support.h" // locale name macros
3334
#include "test_macros.h"
3435

3536
template <class OutIt, class CharT>
3637
void test() {
37-
static_assert(
38-
!std::is_copy_constructible_v<std::basic_format_context<OutIt, CharT>>);
39-
static_assert(
40-
!std::is_copy_assignable_v<std::basic_format_context<OutIt, CharT>>);
41-
// The move operations are implicitly deleted due to the
42-
// deleted copy operations.
43-
static_assert(
44-
!std::is_move_constructible_v<std::basic_format_context<OutIt, CharT>>);
45-
static_assert(
46-
!std::is_move_assignable_v<std::basic_format_context<OutIt, CharT>>);
47-
4838
std::basic_string<CharT> string = MAKE_STRING(CharT, "string");
4939
// The type of the object is an exposition only type. The temporary is needed
5040
// to extend the lifetype of the object since args stores a pointer to the
@@ -118,6 +108,20 @@ void test() {
118108
#endif
119109
}
120110

111+
// std::back_insert_iterator<std::string>, copyable
112+
static_assert(std::is_copy_constructible_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
113+
static_assert(std::is_copy_assignable_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
114+
115+
static_assert(std::is_move_constructible_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
116+
static_assert(std::is_move_assignable_v<std::basic_format_context<std::back_insert_iterator<std::string>, char>>);
117+
118+
// cpp20_output_iterator, move only
119+
static_assert(!std::is_copy_constructible_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
120+
static_assert(!std::is_copy_assignable_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
121+
122+
static_assert(std::is_move_constructible_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
123+
static_assert(std::is_move_assignable_v<std::basic_format_context<cpp20_output_iterator<int*>, char>>);
124+
121125
int main(int, char**) {
122126
test<std::back_insert_iterator<std::basic_string<char>>, char>();
123127
#ifndef TEST_HAS_NO_WIDE_CHARACTERS

0 commit comments

Comments
 (0)