From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4CD463858402 for ; Sat, 18 Nov 2023 21:45:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CD463858402 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4CD463858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700343917; cv=none; b=vCf5GFNvM3p7JDhLTRM7BJkW3eRBDtAajbOLi/0qHahtPrkIOG5B0HdGrJ6FiAMGQnLPK8JL5JN5EvZYLWf4hqj3V+nDNmg/LIwccImm0aXcI434CW8pPsslC0y7TuRS5hnsaqMKphejPEAldB2b8y1crqWBLngw7e8j+qfyoIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700343917; c=relaxed/simple; bh=fAyf7yoxUSniiij8E5rLJ5HSX5BOskliusj3Ee4+Obo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ehCbX/DG5eLgBZxcm5lxByPiLL0z6kURsS4qKbzmwJAvB5OX0Ppf5EoDVStWIR+w3e9IvKJ+jOexFIJxKp3oKOe/FYz0YcNgw0Ip7kQNtn7XoaQrToG4Kebx59hMa1IptmIK88RQWbzNqa/si/9jYxhXOMiL29Fc4PiEyfaVhfQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700343916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0xJ7h6/bVUsm6GXr4BWHjMnvz4CZtVawk7A6UOrWo8o=; b=c73Bd6F0XIj9C6Lk7M7XvOuF0c0B+eExJrOopbGOrmBQbjsXlu+r+OPRr+R/QZotWH3olJ 0PTqngCGtv2Ds5+P1HrPjy++Odk9FzXDrHiCGVDtyyHNqCCflV9eAgFLm/qSRJpQOk8m8+ nylEzz1jCg5TwPFQQXwL4Pq1wjQVajc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-828t4EVsOgeAwR48acEIWA-1; Sat, 18 Nov 2023 16:45:13 -0500 X-MC-Unique: 828t4EVsOgeAwR48acEIWA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B470C1C05EA5; Sat, 18 Nov 2023 21:45:12 +0000 (UTC) Received: from localhost (unknown [10.42.28.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DCE7C1596F; Sat, 18 Nov 2023 21:45:12 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Check string value_type in std::make_format_args [PR112607] Date: Sat, 18 Nov 2023 21:44:36 +0000 Message-ID: <20231118214511.1636561-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,URI_HEX autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Pushed to trunk. Backport to gcc-13 needed too. -- >8 -- 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. --- libstdc++-v3/include/std/format | 12 +++++--- .../testsuite/std/format/arguments/112607.cc | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/std/format/arguments/112607.cc 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{}); -- 2.41.0