From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 590823858D35; Sat, 18 Nov 2023 21:44:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 590823858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700343876; bh=uc1jFohW51eX5KQ18MmBuuSDxBVYtL7vJcV7JYrtLY0=; h=From:To:Subject:Date:From; b=BGW5CslEBdiz+VYakiv3xlP3OWMMgj1jBN9TkP3acEF5zzRK3aVhFoI88f+54GfOJ vPOk5L5JgNzXcl22Icy4o58+Y9/BG49EtzUxniO1eDXTNfUjIKZA+zpI6wnN0G2OU0 MvZqES9rSwNwbAsA0UI/jhjaJ6t3nNFRoIViQrbM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-5588] libstdc++: Check string value_type in std::make_format_args [PR112607] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 41a5ea4cab2c59f9911325281f7df1d3ae846d48 X-Git-Newrev: 279e407a06cc676d8e6e0bb5755b0a804e05377c Message-Id: <20231118214436.590823858D35@sourceware.org> Date: Sat, 18 Nov 2023 21:44:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:279e407a06cc676d8e6e0bb5755b0a804e05377c commit r14-5588-g279e407a06cc676d8e6e0bb5755b0a804e05377c Author: Jonathan Wakely Date: Sat Nov 18 20:56:35 2023 +0000 libstdc++: Check string value_type in std::make_format_args [PR112607] libstdc++-v3/ChangeLog: PR libstdc++/112607 * include/std/format (basic_format_arg::_S_to_arg_type): Check value_type for basic_string_view and basic_string specializations. * testsuite/std/format/arguments/112607.cc: New test. Diff: --- libstdc++-v3/include/std/format | 12 ++++++--- .../testsuite/std/format/arguments/112607.cc | 30 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 7c52cce5dbb..58cd310db4d 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -3220,10 +3220,14 @@ namespace __format return type_identity<__format::__float128_t>(); # endif #endif - else if constexpr (__is_specialization_of<_Td, basic_string_view>) - return type_identity>(); - else if constexpr (__is_specialization_of<_Td, basic_string>) - return type_identity>(); + else if constexpr (__is_specialization_of<_Td, basic_string_view> + || __is_specialization_of<_Td, basic_string>) + { + if constexpr (is_same_v) + return type_identity>(); + else + return type_identity(); + } else if constexpr (is_same_v, const _CharT*>) return type_identity(); else if constexpr (is_same_v, _CharT*>) diff --git a/libstdc++-v3/testsuite/std/format/arguments/112607.cc b/libstdc++-v3/testsuite/std/format/arguments/112607.cc new file mode 100644 index 00000000000..19eec765ea5 --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/arguments/112607.cc @@ -0,0 +1,30 @@ +// { dg-do compile { target c++20 } } + +// PR libstdc++/112607 +// _Normalize does not consider char_type for the basic_string_view case + +#include + +template +struct Alloc +{ + using value_type = T; + Alloc() = default; + template + Alloc(const Alloc&) { } + T* allocate(std::size_t); + void deallocate(T*, std::size_t); + bool operator==(const Alloc&) const; +}; + +template +using String = std::basic_string, Alloc>; + +template<> +struct std::formatter> : std::formatter { + auto format(const String&, auto& ctx) const { + return std::formatter::format(" ", ctx); + } +}; + +std::string str = std::format("{}", String{});