From patchwork Fri Sep 15 09:24:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 140305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp915205vqi; Fri, 15 Sep 2023 02:27:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPzX2EZZXXGotbjWVL9VfdHRyiyO45BGtATlcLFzhD1ukjF0toCIHrHmVh7G5aOMsKlM1U X-Received: by 2002:a50:ec99:0:b0:52f:b1c6:c8a2 with SMTP id e25-20020a50ec99000000b0052fb1c6c8a2mr823981edr.17.1694770070009; Fri, 15 Sep 2023 02:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694770069; cv=none; d=google.com; s=arc-20160816; b=nTbNVfwh7y7IVr3fJ4TWxe042H2Rr7Oz9d8WVbBv/p36NPJl+JHgifZ7UGkyA14bhp lpbXiyXE6ireH5bk23wzEeIL6f0RR7ZDu9g2XK03Z/W7XHgqUMd0IhwkRFSAcGJfvZnz mJZXEmHUHy4lbBr5mSfPyiU1DGviN3LCfgL8Wy70npj5q0Yf6Yg9VSUZVhx+21dvTYY2 3JKpsNEVFk69xvFjwPg9lU2E0yH4OMZRVWv6oApvWTSA6jCTEJl7c18sKHDQzwV35ZGR 1khbUUypVklxD81AugkqonOghmRRnluu4JxjCltO4R6JxQU9UlxzUv1GweBAePOSoYya s4Tw== 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:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=PWmmVMIN67SLZpEgxDYQ4zfR2W5/aMH2eH4PVgtoo9o=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=n9hjovWYVIUHm4I8atsjaLED0Rawv99UN1pap3cXUJ4wx7HLZPUqcvCCIYHVULUt/n TzmgaPlO8ROZrdgafHkceNORJMiR7KooSX+pFY4xNYvXwiBg8OEvRvYjDa2ZRGCeVC8K X7TAd+OMfpgAUNuqJIQRqkQx7OQR5FImFxErsaeyclZDGJmMMT0xYmbRxMiTK2RNRw+F reBonlk3jYLqvSLbJlkNV7lgROuLNQid6NvrghgZILGsIGOrN/2uYA7+NeFh7o14KjI6 iHPRanS6Rkem4M7Da9Src7d3PI9D61X23sfdT+JR42z/sMgw/G7xSdiGQjpwjL28qBX3 xDmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f2zJsqQY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g12-20020aa7c84c000000b0052fbb0b57c2si2745564edt.64.2023.09.15.02.27.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 02:27:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f2zJsqQY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 0BCC73858032 for ; Fri, 15 Sep 2023 09:27:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BCC73858032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694770057; bh=PWmmVMIN67SLZpEgxDYQ4zfR2W5/aMH2eH4PVgtoo9o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=f2zJsqQYNBs/fDZr5LJw11g86tGnW76LYRMVdh3Y0MZJshJ06gLmlvi14FFkuvLPP AgtX/d6obNyTipf0pnw5SvaRAQWJn4AXWfhLyrLbrI+vqpZQB/atH+FBSsmaoBzNT6 IyLJGJqj7ExckncTuDb8moGiZ9rFhSjux3WyqYg4= 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 AD7D23858D1E for ; Fri, 15 Sep 2023 09:26:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD7D23858D1E 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-684-BKzdjTlpNzGQTDzad1GJ2w-1; Fri, 15 Sep 2023 05:26:48 -0400 X-MC-Unique: BKzdjTlpNzGQTDzad1GJ2w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E590C101A550; Fri, 15 Sep 2023 09:26:47 +0000 (UTC) Received: from localhost (unknown [10.42.28.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id A802D1C554; Fri, 15 Sep 2023 09:26:47 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add operator bool to result types (P2497R0) Date: Fri, 15 Sep 2023 10:24:41 +0100 Message-ID: <20230915092647.2192116-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.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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLACK 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: , 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: 1777095220831504051 X-GMAIL-MSGID: 1777095220831504051 Tested x86_64-linux. Pushed to trunk. This was supposed to be in C++23, but I messed up the polls at the last meeting for C++23 ballot resolution. I've heard suggestions that we should just backport it to C++23 as a nice quality of life improvement, but I've also heard objections to any such feature backports (they hurt portability between compilers). This just adds it for C++26. -- >8 -- C++26 adds these convenience conversions. libstdc++-v3/ChangeLog: * include/bits/version.def (to_chars): Define new value for C++26. * include/bits/version.h: Regenerate. * include/std/charconv (to_chars_result::operator bool): New function. (from_chars_result::operator bool): New function. * testsuite/20_util/to_chars/version.cc: Update expected value. * testsuite/20_util/from_chars/result.cc: New test. * testsuite/20_util/to_chars/result.cc: New test. --- libstdc++-v3/include/bits/version.def | 7 + libstdc++-v3/include/bits/version.h | 299 +++++++++--------- libstdc++-v3/include/std/charconv | 6 + .../testsuite/20_util/from_chars/result.cc | 21 ++ .../testsuite/20_util/to_chars/result.cc | 25 ++ .../testsuite/20_util/to_chars/version.cc | 2 +- 6 files changed, 212 insertions(+), 148 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/from_chars/result.cc create mode 100644 libstdc++-v3/testsuite/20_util/to_chars/result.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 8d9b2f71a2e..b7d17c91c34 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -255,6 +255,13 @@ ftms = { ftms = { name = to_chars; + values = { + v = 202306; + cxxmin = 26; + extra_cond = "_GLIBCXX_FLOAT_IS_IEEE_BINARY32 " + "&& _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 " + "&& __SIZE_WIDTH__ >= 32"; + }; values = { v = 201611; cxxmin = 14; diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 01711d38576..7edb6ade3d4 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -62,6 +62,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L friend bool operator==(const to_chars_result&, const to_chars_result&) = default; +#endif +#if __cplusplus > 202302L + constexpr explicit operator bool() const noexcept { return ec == errc{}; } #endif }; @@ -74,6 +77,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L friend bool operator==(const from_chars_result&, const from_chars_result&) = default; +#endif +#if __cplusplus > 202302L + constexpr explicit operator bool() const noexcept { return ec == errc{}; } #endif }; diff --git a/libstdc++-v3/testsuite/20_util/from_chars/result.cc b/libstdc++-v3/testsuite/20_util/from_chars/result.cc new file mode 100644 index 00000000000..637678ac532 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/from_chars/result.cc @@ -0,0 +1,21 @@ +// { dg-do run { target c++26 } } + +#include +#include + +void +test_result() +{ + static_assert( ! std::is_convertible_v ); + static_assert( std::is_constructible_v ); + + std::from_chars_result res{}; + VERIFY( res ); + res.ec = std::errc::invalid_argument; + VERIFY( !res ); +} + +int main() +{ + test_result(); +} diff --git a/libstdc++-v3/testsuite/20_util/to_chars/result.cc b/libstdc++-v3/testsuite/20_util/to_chars/result.cc new file mode 100644 index 00000000000..5284680460a --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/to_chars/result.cc @@ -0,0 +1,25 @@ +// { dg-do run { target c++26 } } + +#include +#include + +#if defined(__cpp_lib_to_chars) && __cpp_lib_to_chars < 202306L +# error "Feature-test macro for std::to_chars has wrong value in " +#endif + +void +test_result() +{ + static_assert( ! std::is_convertible_v ); + static_assert( std::is_constructible_v ); + + std::to_chars_result res{}; + VERIFY( res ); + res.ec = std::errc::invalid_argument; + VERIFY( !res ); +} + +int main() +{ + test_result(); +} diff --git a/libstdc++-v3/testsuite/20_util/to_chars/version.cc b/libstdc++-v3/testsuite/20_util/to_chars/version.cc index 2789afa28ef..f7866ec5377 100644 --- a/libstdc++-v3/testsuite/20_util/to_chars/version.cc +++ b/libstdc++-v3/testsuite/20_util/to_chars/version.cc @@ -6,7 +6,7 @@ #ifndef __cpp_lib_to_chars # error "Feature-test macro for to_chars missing in " -#elif __cpp_lib_to_chars != 201611L +#elif __cpp_lib_to_chars != (__cplusplus == 202302L ? 201611L : 202306L) # error "Feature-test macro for to_chars has wrong value in " #endif