From: Jonathan Wakely Date: Wed, 10 Jul 2024 09:27:24 +0000 (+0100) Subject: libstdc++: Make std::basic_format_context non-copyable [PR114387] X-Git-Tag: basepoints/gcc-16~7595 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d8cd8521185436ea45ed48c5dd481277e9b8a98d;p=thirdparty%2Fgcc.git libstdc++: Make std::basic_format_context non-copyable [PR114387] Users are not supposed to create objects of this type, and there's no reason it needs to be copyable. LWG 4061 makes it non-copyable and non-default constructible. libstdc++-v3/ChangeLog: PR libstdc++/114387 * include/std/format (basic_format_context): Define copy operations as deleted, as per LWG 4061. * testsuite/std/format/context.cc: New test. --- diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 48deba2bcb2..16cee0d3c74 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -3851,6 +3851,12 @@ namespace __format : _M_args(__args), _M_out(std::move(__out)), _M_loc(__loc) { } + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 4061. Should std::basic_format_context be + // default-constructible/copyable/movable? + basic_format_context(const basic_format_context&) = delete; + basic_format_context& operator=(const basic_format_context&) = delete; + template friend _Out2 __format::__do_vformat_to(_Out2, basic_string_view<_CharT2>, @@ -3858,7 +3864,6 @@ namespace __format const locale*); public: - basic_format_context() = default; ~basic_format_context() = default; using iterator = _Out; diff --git a/libstdc++-v3/testsuite/std/format/context.cc b/libstdc++-v3/testsuite/std/format/context.cc new file mode 100644 index 00000000000..5cc5e9c9ba2 --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/context.cc @@ -0,0 +1,36 @@ +// { dg-do compile { target c++20 } } + +#include + +template +concept format_context_reqs = std::is_destructible_v + && (!std::is_default_constructible_v) + && (!std::is_copy_constructible_v) + && (!std::is_move_constructible_v) + && (!std::is_copy_assignable_v) + && (!std::is_move_assignable_v) + && requires (Context& ctx, const Context& cctx) { + typename Context::iterator; + typename Context::char_type; + requires std::same_as, + std::formatter>; + { ctx.locale() } -> std::same_as; + { ctx.out() } -> std::same_as; + { ctx.advance_to(ctx.out()) } -> std::same_as; + { cctx.arg(1) } -> std::same_as>; + }; + +template +constexpr bool +check(std::basic_format_context*) +{ + using context = std::basic_format_context; + static_assert( format_context_reqs ); + static_assert( std::is_same_v ); + static_assert( std::is_same_v ); + return true; +} + +static_assert( check( (std::format_context*)nullptr) ); +static_assert( check( (std::wformat_context*)nullptr) ); +static_assert( check( (std::basic_format_context*)nullptr) );