[libcxx-commits] [libcxx] 36ce0c3 - [libc++][format] Makes format_context copyable.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 21 10:37:02 PST 2022
Author: Mark de Wever
Date: 2022-11-21T19:36:57+01:00
New Revision: 36ce0c3b1e581ca310ae7d0cbc6af002cc5d0251
URL: https://github.com/llvm/llvm-project/commit/36ce0c3b1e581ca310ae7d0cbc6af002cc5d0251
DIFF: https://github.com/llvm/llvm-project/commit/36ce0c3b1e581ca310ae7d0cbc6af002cc5d0251.diff
LOG: [libc++][format] Makes format_context copyable.
This was a bug discovered by @jwakely.
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D137911
Added:
Modified:
libcxx/include/__format/format_context.h
libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index b3c0b3442785..882a6049bb1e 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -85,9 +85,6 @@ class
template <class _Tp>
using formatter_type = formatter<_Tp, _CharT>;
- basic_format_context(const basic_format_context&) = delete;
- basic_format_context& operator=(const basic_format_context&) = delete;
-
_LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context>
arg(size_t __id) const noexcept {
return __args_.get(__id);
diff --git a/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
index 55e55c841b2a..d270a86536de 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
@@ -28,23 +28,13 @@
#include "test_basic_format_arg.h"
#include "test_format_context.h"
+#include "test_iterators.h"
#include "make_string.h"
#include "platform_support.h" // locale name macros
#include "test_macros.h"
template <class OutIt, class CharT>
void test() {
- static_assert(
- !std::is_copy_constructible_v<std::basic_format_context<OutIt, CharT>>);
- static_assert(
- !std::is_copy_assignable_v<std::basic_format_context<OutIt, CharT>>);
- // The move operations are implicitly deleted due to the
- // deleted copy operations.
- static_assert(
- !std::is_move_constructible_v<std::basic_format_context<OutIt, CharT>>);
- static_assert(
- !std::is_move_assignable_v<std::basic_format_context<OutIt, CharT>>);
-
std::basic_string<CharT> string = MAKE_STRING(CharT, "string");
// The type of the object is an exposition only type. The temporary is needed
// to extend the lifetype of the object since args stores a pointer to the
@@ -118,6 +108,20 @@ void test() {
#endif
}
+// 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_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_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>>);
+
int main(int, char**) {
test<std::back_insert_iterator<std::basic_string<char>>, char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
More information about the libcxx-commits
mailing list