From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 07DA1385B513; Thu, 16 Feb 2023 14:38:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07DA1385B513 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676558335; bh=UgHVOhmSc5ebmqkmLC0uioKxGsOe21ZD+8voHYbJbrI=; h=From:To:Subject:Date:From; b=XlnrQr0twd4FGzabaBbppbqbHsJs5ZwfgPV8Lc9Jvo/sWjlSg0pSnu1JXyLac2HA8 szOVipC7VG839I8C5e6/8GrTLddUNvFgCYoJjmMWOJ0IibLzbtC2pgnHD21LqhG1jf hYbZYwHvze6kJFJYoNxawPzTERIM4XP/OKKCEQ98= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-6085] libstdc++: Enable CTAD for std::basic_format_args (LWG 3810) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 916ce577ad109be69a3100fc79b3933d741eb990 X-Git-Newrev: 4024f39941f30570afc32324a8a567519a30e0cd Message-Id: <20230216143855.07DA1385B513@sourceware.org> Date: Thu, 16 Feb 2023 14:38:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4024f39941f30570afc32324a8a567519a30e0cd commit r13-6085-g4024f39941f30570afc32324a8a567519a30e0cd Author: Jonathan Wakely Date: Mon Feb 13 12:22:00 2023 +0000 libstdc++: Enable CTAD for std::basic_format_args (LWG 3810) This was just approved in Issaquah. libstdc++-v3/ChangeLog: * include/std/format (__format::_Arg_store): New class template. (basic_format_args): Remove nested type _Store and add deduction guide from _Arg_store. (basic_format_arg, make_format_args): Adjust. * testsuite/std/format/arguments/lwg3810.cc: New test. Diff: --- libstdc++-v3/include/std/format | 101 ++++++++++++--------- .../testsuite/std/format/arguments/lwg3810.cc | 25 +++++ 2 files changed, 82 insertions(+), 44 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 1cce4ebd45c..b1e627048de 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -2757,6 +2757,10 @@ namespace __format } }; + // [format.arg.store], class template format-arg-store + template + class _Arg_store; + } // namespace __format /// @endcond @@ -2833,6 +2837,9 @@ namespace __format template friend class basic_format_args; + template + friend class __format::_Arg_store; + static_assert(is_trivially_copyable_v<__format::_Arg_value<_Context>>); __format::_Arg_value<_Context> _M_val; @@ -3150,11 +3157,11 @@ namespace __format static_assert( __format::_Arg_max_ <= (1 << _S_packed_type_bits) ); - // [format.arg.store], class template format-arg-store - // XXX: Should this be defined outside the class, so basic_format_args - // can use CTAD with a _Store argument? template - class _Store; + using _Store = __format::_Arg_store<_Context, _Args...>; + + template + friend class __format::_Arg_store; using uint64_t = __UINT64_TYPE__; using _Format_arg = basic_format_arg<_Context>; @@ -3215,52 +3222,60 @@ namespace __format } }; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3810. CTAD for std::basic_format_args + template + basic_format_args(__format::_Arg_store<_Context, _Args...>) + -> basic_format_args<_Context>; + + template + auto + make_format_args(_Args&&... __fmt_args) noexcept; + // An array of type-erased formatting arguments. - template - template - class basic_format_args<_Context>::_Store - { - friend class basic_format_args; + template + class __format::_Arg_store + { + friend std::basic_format_args<_Context>; - template - friend auto - make_format_args(_Argz&&...) noexcept; + template + friend auto + std::make_format_args(_Argz&&...) noexcept; - // For a sufficiently small number of arguments we only store values. - // basic_format_args can get the types from the _Args pack. - static constexpr bool _S_values_only - = sizeof...(_Args) <= _S_max_packed_args; + // For a sufficiently small number of arguments we only store values. + // basic_format_args can get the types from the _Args pack. + static constexpr bool _S_values_only + = sizeof...(_Args) <= basic_format_args<_Context>::_S_max_packed_args; - using _Element_t - = __conditional_t<_S_values_only, - __format::_Arg_value<_Context>, - basic_format_arg<_Context>>; + using _Element_t + = __conditional_t<_S_values_only, + __format::_Arg_value<_Context>, + basic_format_arg<_Context>>; - _Element_t _M_args[sizeof...(_Args)]; + _Element_t _M_args[sizeof...(_Args)]; - template - static _Element_t - _S_make_elt(_Tp& __v) - { - basic_format_arg<_Context> __arg(__v); - if constexpr (_S_values_only) - return __arg._M_val; - else - return __arg; - } + template + static _Element_t + _S_make_elt(_Tp& __v) + { + basic_format_arg<_Context> __arg(__v); + if constexpr (_S_values_only) + return __arg._M_val; + else + return __arg; + } - template - requires (sizeof...(_Tp) == sizeof...(_Args)) - [[__gnu__::__always_inline__]] - _Store(_Tp&... __a) noexcept - : _M_args{_S_make_elt(__a)...} - { } - }; + template + requires (sizeof...(_Tp) == sizeof...(_Args)) + [[__gnu__::__always_inline__]] + _Arg_store(_Tp&... __a) noexcept + : _M_args{_S_make_elt(__a)...} + { } + }; template - template requires (sizeof...(_Args) == 0) - class basic_format_args<_Context>::_Store<_Args...> - { }; + class __format::_Arg_store<_Context> + { }; template template @@ -3300,10 +3315,8 @@ namespace __format inline auto make_format_args(_Args&&... __fmt_args) noexcept { - using _Fmt_args = basic_format_args<_Context>; using _Fmt_arg = basic_format_arg<_Context>; - using _Store = typename _Fmt_args::template - _Store>...>; return _Store(__fmt_args...); } diff --git a/libstdc++-v3/testsuite/std/format/arguments/lwg3810.cc b/libstdc++-v3/testsuite/std/format/arguments/lwg3810.cc new file mode 100644 index 00000000000..c1be229040f --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/arguments/lwg3810.cc @@ -0,0 +1,25 @@ +// { dg-do compile { target c++20 } } +// { dg-options "-std=gnu++20" } + +// LWG 3810. CTAD for std::basic_format_args + +#include + +auto args_store = std::make_format_args(1,2,3); +std::basic_format_args args = args_store; +static_assert(std::is_same_v); + + +template +void foo(std::basic_format_args); + +void +test_ctad() +{ + using std::basic_format_args; + using std::make_format_args; + using SomeContext = std::wformat_context; + + // foo(make_format_args(…)); // won't work + foo(basic_format_args(make_format_args(1, 2, 3))); // should work +}