From patchwork Fri Aug 18 11:31:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 136013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1331230vqi; Fri, 18 Aug 2023 04:32:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwhmJTFBW+/Ang0JTEEAibxmpACgste+ziKud9+lieWkpc7W/VBK3WzOZ+SzPg7ZFKdav2 X-Received: by 2002:a17:906:7693:b0:99d:e142:4646 with SMTP id o19-20020a170906769300b0099de1424646mr1867613ejm.18.1692358379301; Fri, 18 Aug 2023 04:32:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692358379; cv=none; d=google.com; s=arc-20160816; b=GqBtvbTckUyoy0uP/9lDL7vfCpP4qcBlY6C2d+DyWuek+3CHXpDvGpGrxFvEBaeIhw VfWjxHjf60O4Zw+s/xllMgNwGknAqanWxOJx8GrQUlKlaa2NKKYc5h9tQ4sVc9wRe/ay EoXMec5uxtKTkuwfeF4a3ZOjK9UjgHn3uvNcP4akZSbEhjnYHMWIJ9eXJy/M3mmln9sO lLNwVUYitFDOhjxVZAFDBNzv4stSGmJyY3zsFK8001wbQ0sv74yzOQdJ4/itExfRWkXp 9vHvwTLw0uPMjOVAZGIpoW10Gs6StFSmDILHxi3ZRO+HQxL/7JRNxbynESDecPDuoBMA JWng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=ltAR3Get+JORlGg+RGbE511sSZeP5Cy6+cNG63xQjjU=; fh=sC8lnOfyH6gL5FYlMbZ1VDz6qVPMj/3ViLJWKNUCUgQ=; b=eTuFVI/mNg+yWacV8HhYLXevcMCr8xoYhVWtjSn+EJ8BDs2HgH8FGeuf/wqjf/NPJc K2Z5Q9bY81kVi//VHLnzLY05fVesTZCLv4yssDWX/OqgX2Z2vHUokCRmt0T86fSxG15k ayLJIT2V0jfOPOI+d50YV0mPDQ+XUpBap5Rqp/OXLWiPj+0AYh+fGEzua4bXGbAWJlzB VpWeKC8/qzfXBy1NQ5IYu3YJJ06wmvCxfluD03ya/+YUOkD4pCYdUlqm+/mLTBcdl0Nl JgrhATETw4i6bWuov/we4AZvbyk54Na/jT6uOonzj8hFt599Mvr7SCbtZQdgyUlrUF2g NyUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sQHtpIYQ; 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=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xa6-20020a170907b9c600b00992e22a6409si1237421ejc.553.2023.08.18.04.32.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 04:32:59 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=sQHtpIYQ; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99C5B3870C00 for ; Fri, 18 Aug 2023 11:32:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99C5B3870C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692358353; bh=ltAR3Get+JORlGg+RGbE511sSZeP5Cy6+cNG63xQjjU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=sQHtpIYQ1FAZ6wCZlUs7O3eI5P7vp/SyZAnA891paMDABzTlpx4JrbDOQleiWstiJ 3PVvbyz9FKp8Ea6U2VTGgzOopl4gNkBebzU10guslPf5bTGU6DaFMeHGXkJTZcqIxT P4jkAxiTx0/kyVO3AHrSUhW5pc7X49vnjTU+hR/A= 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 695133858401 for ; Fri, 18 Aug 2023 11:31:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 695133858401 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-k9_1uskVPqqsTKTc6Z2VLQ-1; Fri, 18 Aug 2023 07:31:47 -0400 X-MC-Unique: k9_1uskVPqqsTKTc6Z2VLQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B6178011AD; Fri, 18 Aug 2023 11:31:47 +0000 (UTC) Received: from localhost (unknown [10.42.28.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2620D6B2A9; Fri, 18 Aug 2023 11:31:47 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Replace non-type-dependent uses of wchar_t in and Date: Fri, 18 Aug 2023 12:31:15 +0100 Message-ID: <20230818113147.1360843-1-jwakely@redhat.com> In-Reply-To: <20230818084437.1297460-1-jwakely@redhat.com> References: <20230818084437.1297460-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774566380115384162 X-GMAIL-MSGID: 1774566380115384162 This should be really fixed now! Tested x86_64-linux. Pushed to trunk. -- >8 -- This is one more piece of the rework to make wchar_t support in std::format depend on _GLIBCXX_USE_WCHAR_T. In the __to_wstring_numeric function is called with arguments that aren't type-dependent, so a declaration needs to be available, or the calls need to be guarded by _GLIBCXX_USE_WCHAR_T. In there is a similarly non-type-dependent call to std::format with a wchar_t format string, which is ill-formed when the wchar_t overloads of std::format are not declared. Use _GLIBCXX_WIDEN to make it type-dependent. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (operator<<): Make uses of wide strings with streams and std::format type-dependent on _CharT. * include/std/format [!_GLIBCXX_USE_WCHAR_T] Do not use __to_wstring_numeric. --- libstdc++-v3/include/bits/chrono_io.h | 17 ++++++----------- libstdc++-v3/include/std/format | 10 ++++++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index e16302baf84..d558802e7d8 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -2390,15 +2390,14 @@ namespace __detail __os2.imbue(__os.getloc()); __os2 << __wdi.weekday(); const auto __i = __wdi.index(); - if constexpr (is_same_v<_CharT, char>) - __os2 << std::format("[{}", __i); - else - __os2 << std::format(L"[{}", __i); - basic_string_view<_CharT> __s = _GLIBCXX_WIDEN(" is not a valid index]"); + basic_string_view<_CharT> __s + = _GLIBCXX_WIDEN("[ is not a valid index]"); + __os2 << __s[0]; + __os2 << std::format(_GLIBCXX_WIDEN("{}"), __i); if (__i >= 1 && __i <= 5) __os2 << __s.back(); else - __os2 << __s; + __os2 << __s.substr(1); __os << __os2.view(); return __os; } @@ -2457,11 +2456,7 @@ namespace __detail // As above, just write straight to a stringstream, as if by "{:L}/last" basic_stringstream<_CharT> __os2; __os2.imbue(__os.getloc()); - __os2 << __mdl.month(); - if constexpr (is_same_v<_CharT, char>) - __os2 << "/last"; - else - __os2 << L"/last"; + __os2 << __mdl.month() << _GLIBCXX_WIDEN("/last"); __os << __os2.view(); return __os; } diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 0b1ae8201af..648f847ad96 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -1142,13 +1142,15 @@ namespace __format basic_string_view<_CharT> __str; if constexpr (is_same_v) __str = __narrow_str; +#ifdef _GLIBCXX_USE_WCHAR_T else { size_t __n = __narrow_str.size(); auto __p = (_CharT*)__builtin_alloca(__n * sizeof(_CharT)); - __to_wstring_numeric(__narrow_str.data(), __n, __p); + std::__to_wstring_numeric(__narrow_str.data(), __n, __p); __str = {__p, __n}; } +#endif if (_M_spec._M_localized) { @@ -1624,11 +1626,13 @@ namespace __format basic_string_view<_CharT> __str; if constexpr (is_same_v<_CharT, char>) __str = __narrow_str; +#ifdef _GLIBCXX_USE_WCHAR_T else { __wstr = std::__to_wstring_numeric(__narrow_str); __str = __wstr; } +#endif if (_M_spec._M_localized) { @@ -2290,12 +2294,14 @@ namespace __format basic_string_view<_CharT> __str; if constexpr (is_same_v<_CharT, char>) __str = string_view(__buf, __n); +#ifdef _GLIBCXX_USE_WCHAR_T else { auto __p = (_CharT*)__builtin_alloca(__n * sizeof(_CharT)); - __to_wstring_numeric(__buf, __n, __p); + std::__to_wstring_numeric(__buf, __n, __p); __str = wstring_view(__p, __n); } +#endif #if _GLIBCXX_P2518R3 if (_M_spec._M_zero_fill)