From patchwork Fri Sep 23 11:59:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp179330wrt; Fri, 23 Sep 2022 05:02:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UxbJf7SrIC8qTg933onidEdVCE6261mSt8y5k2uhex9TqDV+SGY+LntU8btc3gJJL6jRD X-Received: by 2002:a17:907:8a17:b0:782:6e72:7aba with SMTP id sc23-20020a1709078a1700b007826e727abamr5246313ejc.474.1663934554852; Fri, 23 Sep 2022 05:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663934554; cv=none; d=google.com; s=arc-20160816; b=Le2raAYq3IFRRoUWTGgW0t6rh5AmbRo4T+LHoZSbSZlLdhLfqSHWLNKv8QK89sUJKy tIE9E2JYzmF844bstvSW64duasneAvJl1BDtgvwMLk4qv0Pn7urfF4e3LG/Oww6r50Uy gLVPicFR03tvFw/tqxkgvCpGSUxsRPUglxiftkP0fTUlp2ZLfF5aI2LqYGX9Eaw2FaVe xa5rbqWvkiMlVf99QJVp3G614uEENLU6K1wQuoosvxmFtJ8qbXsBdTzy5DZq3cKehP/G OGXzc3Qqj/2kQ6HOaekTXIAyF+ccu5PeMUQmVr4MjuFSj1Oz73KFn3+iuDgwHf/fpk6F Z//Q== 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=WopEYyZyp7OLlLvP/e4SSX5wjuoeVcD4xwtk32bo8sY=; b=MHsl0/A8qV+7KeDHg10uqSoqRKNPlnG37ykPAHH+Oj8yOYZpEoikVzBgcLKytWIJAv gXTVCrV2LM5WBfucH37aIq+5wUOa/ontfTpIlNn86uERtcweWOno6wPgXgBqMtFO0UJf KHpBHvcYGVgYO34+hWEgFnm+7TqP5k7YIB+O1RGMB0Gx5TtCZ8O9rCQQUozij0mN2yqw hQAc7t6TxG/dr2rmHg7v/eNLDe+GVVOqevDg2VvY98VCE4pYdmn2TG5KDw51efzPZaAf 8NQYFXp0FXz4wSRhZVV9WhhJWY5+4+QIj1CabTMTiP1PYJfuCNrAVHi2R+ROl7mFPKLV 4WdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dGvYYjEs; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w6-20020a170906130600b00775bde41c57si6508683ejb.171.2022.09.23.05.02.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 05:02:34 -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=dGvYYjEs; 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 C0AC3385737C for ; Fri, 23 Sep 2022 12:00:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0AC3385737C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663934457; bh=WopEYyZyp7OLlLvP/e4SSX5wjuoeVcD4xwtk32bo8sY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dGvYYjEs2BYpjGca909Yp0YZJvJRPZFII7fiuILMm9DxcI1WF6q/7NoFr1EYFjP2X XIt2JVu3zDiSMJEDt5J6erBRD9pdDJfYuRWxsiPkV7RGbjOw2Innduv3/lbfJ7IA8U QNKsHg8HU8sYLY5ruuqDPfwLnlukFtqYZNOA3Aik= 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 013253858C52 for ; Fri, 23 Sep 2022 11:59:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 013253858C52 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-119-uovTaJjHPR6roxcAQ93ICg-1; Fri, 23 Sep 2022 07:59:51 -0400 X-MC-Unique: uovTaJjHPR6roxcAQ93ICg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 388073C11042; Fri, 23 Sep 2022 11:59:51 +0000 (UTC) Received: from localhost (unknown [10.33.36.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAFC540C6EC2; Fri, 23 Sep 2022 11:59:50 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Enable constexpr std::bitset for debug mode Date: Fri, 23 Sep 2022 12:59:50 +0100 Message-Id: <20220923115950.1327715-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744761839623241876?= X-GMAIL-MSGID: =?utf-8?q?1744761839623241876?= Tested x86_64-linux. Pushed to trunk. As I said in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107015 I think we should just get rid of __debug::bitset, it is useless except for C++98, where it's ABI-incompatible with C++11 and later. -- >8 -- We already disable all debug mode checks for C++11 and later, so we can easily make everything constexpr. This fixes the FAIL results for the new tests when using -D_GLIBCXX_DEBUG. Also fix some other tests failing with non-default test flags. libstdc++-v3/ChangeLog: * include/debug/bitset (__debug::bitset): Add constexpr to all member functions. (operator&, operator|, operator^): Add inline and constexpr. (operator>>, operator<<): Add inline. * testsuite/20_util/bitset/access/constexpr.cc: Only check using constexpr std::string for the cxx11 ABI. * testsuite/20_util/bitset/cons/constexpr_c++23.cc: Likewise. * testsuite/20_util/headers/bitset/synopsis.cc: Check constexpr for C++23. --- libstdc++-v3/include/debug/bitset | 43 ++++++++++++++++--- .../20_util/bitset/access/constexpr.cc | 2 + .../20_util/bitset/cons/constexpr_c++23.cc | 2 + .../20_util/headers/bitset/synopsis.cc | 9 ++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index 4c0af03c255..9335fe441a3 100644 --- a/libstdc++-v3/include/debug/bitset +++ b/libstdc++-v3/include/debug/bitset @@ -141,6 +141,7 @@ namespace __debug : _Base(__val) { } template + _GLIBCXX23_CONSTEXPR explicit bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str, typename std::basic_string<_CharT, _Traits, _Alloc>::size_type @@ -152,6 +153,7 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 396. what are characters zero and one. template + _GLIBCXX23_CONSTEXPR bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str, typename std::basic_string<_CharT, _Traits, _Alloc>::size_type __pos, @@ -160,10 +162,12 @@ namespace __debug _CharT __zero, _CharT __one = _CharT('1')) : _Base(__str, __pos, __n, __zero, __one) { } + _GLIBCXX23_CONSTEXPR bitset(const _Base& __x) : _Base(__x) { } #if __cplusplus >= 201103L template + _GLIBCXX23_CONSTEXPR explicit bitset(const _CharT* __str, typename std::basic_string<_CharT>::size_type __n @@ -173,6 +177,7 @@ namespace __debug #endif // 23.3.5.2 bitset operations: + _GLIBCXX23_CONSTEXPR bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT { @@ -180,6 +185,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT { @@ -187,6 +193,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT { @@ -194,6 +201,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT { @@ -201,6 +209,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT { @@ -208,6 +217,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& set() _GLIBCXX_NOEXCEPT { @@ -217,6 +227,7 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 186. bitset::set() second parameter should be bool + _GLIBCXX23_CONSTEXPR bitset<_Nb>& set(size_t __pos, bool __val = true) { @@ -224,6 +235,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& reset() _GLIBCXX_NOEXCEPT { @@ -231,6 +243,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& reset(size_t __pos) { @@ -238,10 +251,12 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb> operator~() const _GLIBCXX_NOEXCEPT { return bitset(~_M_base()); } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& flip() _GLIBCXX_NOEXCEPT { @@ -249,6 +264,7 @@ namespace __debug return *this; } + _GLIBCXX23_CONSTEXPR bitset<_Nb>& flip(size_t __pos) { @@ -259,6 +275,7 @@ namespace __debug // element access: // _GLIBCXX_RESOLVE_LIB_DEFECTS // 11. Bitset minor problems + _GLIBCXX23_CONSTEXPR reference operator[](size_t __pos) { @@ -288,6 +305,7 @@ namespace __debug #endif template + _GLIBCXX23_CONSTEXPR std::basic_string<_CharT, _Traits, _Alloc> to_string() const { return _M_base().template to_string<_CharT, _Traits, _Alloc>(); } @@ -295,6 +313,7 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 396. what are characters zero and one. template + _GLIBCXX23_CONSTEXPR std::basic_string<_CharT, _Traits, _Alloc> to_string(_CharT __zero, _CharT __one = _CharT('1')) const { @@ -305,6 +324,7 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 434. bitset::to_string() hard to use. template + _GLIBCXX23_CONSTEXPR std::basic_string<_CharT, _Traits, std::allocator<_CharT> > to_string() const { return to_string<_CharT, _Traits, std::allocator<_CharT> >(); } @@ -312,12 +332,14 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 853. to_string needs updating with zero and one. template + _GLIBCXX23_CONSTEXPR std::basic_string<_CharT, _Traits, std::allocator<_CharT> > to_string(_CharT __zero, _CharT __one = _CharT('1')) const { return to_string<_CharT, _Traits, std::allocator<_CharT> >(__zero, __one); } template + _GLIBCXX23_CONSTEXPR std::basic_string<_CharT, std::char_traits<_CharT>, std::allocator<_CharT> > to_string() const @@ -327,6 +349,7 @@ namespace __debug } template + _GLIBCXX23_CONSTEXPR std::basic_string<_CharT, std::char_traits<_CharT>, std::allocator<_CharT> > to_string(_CharT __zero, _CharT __one = _CharT('1')) const @@ -335,12 +358,14 @@ namespace __debug std::allocator<_CharT> >(__zero, __one); } + _GLIBCXX23_CONSTEXPR std::basic_string, std::allocator > to_string() const { return to_string,std::allocator >(); } + _GLIBCXX23_CONSTEXPR std::basic_string, std::allocator > to_string(char __zero, char __one = '1') const { @@ -351,6 +376,7 @@ namespace __debug using _Base::count; using _Base::size; + _GLIBCXX23_CONSTEXPR bool operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT { return _M_base() == __rhs._M_base(); } @@ -366,45 +392,52 @@ namespace __debug using _Base::any; using _Base::none; + _GLIBCXX23_CONSTEXPR bitset<_Nb> operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT { return bitset<_Nb>(_M_base() << __pos); } + _GLIBCXX23_CONSTEXPR bitset<_Nb> operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT { return bitset<_Nb>(_M_base() >> __pos); } + _GLIBCXX23_CONSTEXPR _Base& _M_base() _GLIBCXX_NOEXCEPT { return *this; } + _GLIBCXX23_CONSTEXPR const _Base& _M_base() const _GLIBCXX_NOEXCEPT { return *this; } }; template - bitset<_Nb> + _GLIBCXX23_CONSTEXPR + inline bitset<_Nb> operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT { return bitset<_Nb>(__x) &= __y; } template - bitset<_Nb> + _GLIBCXX23_CONSTEXPR + inline bitset<_Nb> operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT { return bitset<_Nb>(__x) |= __y; } template - bitset<_Nb> + _GLIBCXX23_CONSTEXPR + inline bitset<_Nb> operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT { return bitset<_Nb>(__x) ^= __y; } template - std::basic_istream<_CharT, _Traits>& + inline std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x) { return __is >> __x._M_base(); } template - std::basic_ostream<_CharT, _Traits>& + inline std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x) { return __os << __x._M_base(); } diff --git a/libstdc++-v3/testsuite/20_util/bitset/access/constexpr.cc b/libstdc++-v3/testsuite/20_util/bitset/access/constexpr.cc index 7c39fcadc6c..53bb07f9498 100644 --- a/libstdc++-v3/testsuite/20_util/bitset/access/constexpr.cc +++ b/libstdc++-v3/testsuite/20_util/bitset/access/constexpr.cc @@ -27,6 +27,7 @@ test_indexing() static_assert( test_indexing() ); +#if _GLIBCXX_USE_CXX11_ABI constexpr bool test_to_string() { @@ -35,6 +36,7 @@ test_to_string() } static_assert( test_to_string() ); +#endif constexpr bool test_to_ulong() diff --git a/libstdc++-v3/testsuite/20_util/bitset/cons/constexpr_c++23.cc b/libstdc++-v3/testsuite/20_util/bitset/cons/constexpr_c++23.cc index 92bfebe8f66..532fc9dc4d5 100644 --- a/libstdc++-v3/testsuite/20_util/bitset/cons/constexpr_c++23.cc +++ b/libstdc++-v3/testsuite/20_util/bitset/cons/constexpr_c++23.cc @@ -24,6 +24,7 @@ constexpr bool test_ntbs() static_assert( test_ntbs() ); +#if _GLIBCXX_USE_CXX11_ABI constexpr bool test_string() { using S = std::string; @@ -51,3 +52,4 @@ constexpr bool test_wstring() } static_assert( test_wstring() ); +#endif diff --git a/libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc index e7ea4f89a4a..ed5604b6b22 100644 --- a/libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc +++ b/libstdc++-v3/testsuite/20_util/headers/bitset/synopsis.cc @@ -27,17 +27,26 @@ # define NOTHROW #endif +#if __cplusplus > 202002L +# define CONSTEXPR constexpr +#else +# define CONSTEXPR +#endif + namespace std { template class bitset; // 23.3.5.3 bitset operations: template + CONSTEXPR bitset operator&(const bitset&, const bitset&) NOTHROW; template + CONSTEXPR bitset operator|(const bitset&, const bitset&) NOTHROW; template + CONSTEXPR bitset operator^(const bitset&, const bitset&) NOTHROW; template