From patchwork Sat Mar 23 11:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1915131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dE65nRKk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V1xLx0hRnz1yXr for ; Sat, 23 Mar 2024 22:10:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6C40385829A for ; Sat, 23 Mar 2024 11:10:30 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 8031E38582A0 for ; Sat, 23 Mar 2024 11:10:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8031E38582A0 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 8031E38582A0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711192209; cv=none; b=wc9bEqqzzYnDgYGrRQ/ZPHmX/sT9tFzVQzTC255hMN6bRNfHH6ZC2oxyBaqYwtq44uCgnA9nb+MN5Yb6NEvi71PdxgiYfWFUjF+POD0zh6Oxg4FgPN8VJ06mr2CPZbwRjBdrC1lBewVl24+2AywegTNW3BnSTQGHgxL+t2Ovxfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711192209; c=relaxed/simple; bh=fqYgNgY4L1wJFjglryKU4AplUyRwy5+Urk34Ggk6BnI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ouhhnxsPyJEmAKgWfFQvyZDeKU4eduYKDjoZf+4ipPkeuvZ3flae/ioEcYvy23yFdNG4kCXMCiurf1ugfjdJHot6L69enTL9VyViBZIPv83NAnA84g7nuzge/Xqg+rffdDTrcWeZY+yGwDmLQGeDcvyrsmN3e1qwsgjfMrivSqo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711192206; 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=uYhivRhl7b8/3e/Zl1OmoRnp0mJf3VmY3Bew1YyTjlM=; b=dE65nRKkS4zQ4wS9ZucODHaKELbyBV3Xtk3lNmRD/j4Ncsp4E57lHy28Y2pMaLZR7n9Ksw jKvVd3dM4QR98cQDWnJBpPViNfmIjcCBE54uZzCyFSN79B/lsN4OSeT9UWbPFvDIaKOtOI tALN6Krad7RF48xZ7+7G0G4+6k+JS98= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-330-oXbxpB_PNeOL8TYF5wBgbA-1; Sat, 23 Mar 2024 07:10:04 -0400 X-MC-Unique: oXbxpB_PNeOL8TYF5wBgbA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 E1E91101A523; Sat, 23 Mar 2024 11:10:03 +0000 (UTC) Received: from localhost (unknown [10.42.28.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE70C2166B31; Sat, 23 Mar 2024 11:10:03 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Disable std::formatter specializations (LWG 3944) Date: Sat, 23 Mar 2024 11:09:52 +0000 Message-ID: <20240323110959.426090-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested aarch64-linux. Pushed to trunk. -- >8 -- This was just approved in Tokyo as a DR for C++23. It doesn't affect us yet, because we don't implement the __cpp_lib_format_ranges features. We can add the disabled specializations and add a testcase now though. libstdc++-v3/ChangeLog: * include/std/format (formatter): Disable specializations that would allow sequences of narrow characters to be formatted as wchar_t without conversion, as per LWG 3944. * testsuite/std/format/formatter/lwg3944.cc: New test. --- libstdc++-v3/include/std/format | 23 ++++++++++++++ .../testsuite/std/format/formatter/lwg3944.cc | 31 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 613016d1a10..22dcb5f24bd 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -2478,6 +2478,29 @@ namespace __format }; /// @} +#if defined _GLIBCXX_USE_WCHAR_T && __cpp_lib_format_ranges + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3944. Formatters converting sequences of char to sequences of wchar_t + + namespace __format { struct __disabled; } + + // std::formatter<__disabled, C> uses the primary template, which is disabled. + template<> + struct formatter + : private formatter<__format::__disabled, wchar_t> { }; + template<> + struct formatter + : private formatter<__format::__disabled, wchar_t> { }; + template + struct formatter + : private formatter<__format::__disabled, wchar_t> { }; + template + struct formatter, wchar_t> + : private formatter<__format::__disabled, wchar_t> { }; + template + struct formatter, wchar_t> + : private formatter<__format::__disabled, wchar_t> { }; +#endif /// @cond undocumented namespace __format diff --git a/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc new file mode 100644 index 00000000000..ff5f075bcc8 --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc @@ -0,0 +1,31 @@ +// { dg-do compile { target c++20 } } +// { dg-options "-Wno-unused-result" } + +// LWG 3944. Formatters converting sequences of char to sequences of wchar_t + +#include + +void test_lwg3944() +{ + // Ill-formed in C++20 and C++23 + const char* cstr = "hello"; + char* str = const_cast(cstr); + std::format(L"{}", str); // { dg-error "here" } + std::format(L"{}",cstr); // { dg-error "here" } + + // Ill-formed in C++20 + // In C++23 they give L"['h', 'e', 'l', 'l', 'o']" + std::format(L"{}", "hello"); // { dg-error "here" } + std::format(L"{}", std::string_view("hello")); // { dg-error "here" } + std::format(L"{}", std::string("hello")); // { dg-error "here" } +#ifdef __cpp_lib_format_ranges + // LWG 3944 does not change this, it's still valid. + std::format(L"{}", std::vector{'h', 'e', 'l', 'l', 'o'}); +#endif +} + +// { dg-error "std::formatter must be specialized" "" { target *-*-* } 0 } +// { dg-prune-output "use of deleted function" } +// { dg-prune-output "no matching function" } +// { dg-prune-output "has no member named 'parse'" } +// { dg-prune-output "not a constant expression" }