diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-07-10 10:27:24 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-07-10 22:05:22 +0100 |
commit | d8cd8521185436ea45ed48c5dd481277e9b8a98d (patch) | |
tree | 9f8ef341aca28631a2de618f91b410d127d4e818 /libstdc++-v3/testsuite | |
parent | 9f758953eb2cb89e306025dc232ae20da6cb860a (diff) | |
download | gcc-d8cd8521185436ea45ed48c5dd481277e9b8a98d.zip gcc-d8cd8521185436ea45ed48c5dd481277e9b8a98d.tar.gz gcc-d8cd8521185436ea45ed48c5dd481277e9b8a98d.tar.bz2 |
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.
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r-- | libstdc++-v3/testsuite/std/format/context.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/std/format/context.cc b/libstdc++-v3/testsuite/std/format/context.cc new file mode 100644 index 0000000..5cc5e9c --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/context.cc @@ -0,0 +1,36 @@ +// { dg-do compile { target c++20 } } + +#include <format> + +template<typename Context> +concept format_context_reqs = std::is_destructible_v<Context> + && (!std::is_default_constructible_v<Context>) + && (!std::is_copy_constructible_v<Context>) + && (!std::is_move_constructible_v<Context>) + && (!std::is_copy_assignable_v<Context>) + && (!std::is_move_assignable_v<Context>) + && requires (Context& ctx, const Context& cctx) { + typename Context::iterator; + typename Context::char_type; + requires std::same_as<typename Context::template formatter_type<int>, + std::formatter<int, typename Context::char_type>>; + { ctx.locale() } -> std::same_as<std::locale>; + { ctx.out() } -> std::same_as<typename Context::iterator>; + { ctx.advance_to(ctx.out()) } -> std::same_as<void>; + { cctx.arg(1) } -> std::same_as<std::basic_format_arg<Context>>; + }; + +template<typename Out, typename charT> +constexpr bool +check(std::basic_format_context<Out, charT>*) +{ + using context = std::basic_format_context<Out, charT>; + static_assert( format_context_reqs<context> ); + static_assert( std::is_same_v<typename context::iterator, Out> ); + static_assert( std::is_same_v<typename context::char_type, charT> ); + return true; +} + +static_assert( check( (std::format_context*)nullptr) ); +static_assert( check( (std::wformat_context*)nullptr) ); +static_assert( check( (std::basic_format_context<char*, char>*)nullptr) ); |