From patchwork Sat Nov 18 21:44:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 166657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1398707vqn; Sat, 18 Nov 2023 14:50:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5M14HGysJJBSfwVV4d23PBFAoZCnMaN/etr99KRaEaXY9tsJyy04Sz3SQnf/kP2GdBFQ9 X-Received: by 2002:a05:6214:ccc:b0:668:e6f7:3d48 with SMTP id 12-20020a0562140ccc00b00668e6f73d48mr5107438qvx.19.1700347810748; Sat, 18 Nov 2023 14:50:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700347810; cv=pass; d=google.com; s=arc-20160816; b=icM7GLq6+6OKfgoQd+j9oHERm0KJydNr3IKiB45TZpFE2nwlVUdEifV5OK69fsJrcC /WmMHssNBTz+ZRz4r/0Qmoh9yjLDZJ8VoBUJc7RcdxF7YpSvJJfz89zdsD+PW0+GYzcR xcmTj6Y8j8HkU9FeaDl91HSDG6LWxoDA3DaBbH1Q23yWQApPTh6UcDrvmj3W+Iyd7HxY YRiJ3ClYdm16sB/FAhaosAKqqo0r6X6m+dMI1JGBioCW53SLsRLrgPFB0PbUYyrBemuU JsguY/E2v5rKDlsvjYQylhBQ5LCX1rEvhWr4a5NlP1Vc0pZ2vqwBJ/R2xGfRyrjADC4E pdxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=0xJ7h6/bVUsm6GXr4BWHjMnvz4CZtVawk7A6UOrWo8o=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=aXx2MY6y4iupGezCcYq04aaXVPSsTZ92c3lR5wuIuHMLYh6SWB7m5f7QZ1zjc1EcEt 5oUmxFLorlmV0LT3/60EgyDJfrvyf3KdxNAaYJKzrB+hImm1CZktuIkhCQqKAurSHlhk /+A5YNCIZRnBs4XiLBiFWrQgyF5kr30Qiw5Yi50q93gwbAxy2qnivDQXn70CODHMkJqL MRBMuWUf+XRw6vfTLj/QisyhZiM+xYCJOkcqYlTQp24WXANmyhF7oB9zt7h9RI/xImQj QKW6plaarR9W6lAEg4f3xudGES7ubRMScrkIPdYj3TZSMz9k84+ms/wXLpfcsEWmStv5 kcdw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FVF6HuAw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qb8-20020ad44708000000b0065d1380dd16si4358800qvb.336.2023.11.18.14.50.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 14:50:10 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FVF6HuAw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2501F385771D for ; Sat, 18 Nov 2023 21:45:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 C2D903858CD1 for ; Sat, 18 Nov 2023 21:45:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2D903858CD1 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 C2D903858CD1 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=1700343915; cv=none; b=tT0Dx/IPHdOj3hzcA5xzzeWpr8L6snvmqRuD56UoAFKygrEw29wkAuYy6/tsrH76VihY1l1Vrs6G0EvnmrEA5RLUSrpeBD5DbpVS83KwGT5Qb67fZErAveopfIG2nlrljKFAjuXVoPaXyrvfLyF8TOPP/DORwoaNjHVQlN7F8LM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700343915; c=relaxed/simple; bh=fAyf7yoxUSniiij8E5rLJ5HSX5BOskliusj3Ee4+Obo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Hr15hoTQfI7swQ6/1442kAPvLJ+hF3ibzxn4Vk1c4va9wwwWuq9v0rCwarykl1eUQF1TWgUp12K6T1GXydgi+K0UZQspnxB666Y/c+n+MVt3WOxlOKNFocPjCkaKdB8jxzRBJOuV6wUN8fVqH2kRrotHZpn4HA/heBHVjVJiEyM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700343914; 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=FVF6HuAwEZrIlaJMOunkxdbmrC5V4tnJBu5hnbU8/oiGXs5BQnxgelDICfNuhyr06z3e6x nTLz5teKF+NaTQ32G8u0CxhUL6DVR0jx2Y4ZI/zBDksFu0zNyP74p44HwKne8LIKE+KZ9/ sX/VmvJ7XREO/Ew196OtNmle0PNdx0o= 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 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782943905810544040 X-GMAIL-MSGID: 1782943905810544040 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{});