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: 57965 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1EA243851AB5 for ; Fri, 23 Sep 2022 12:00:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EA243851AB5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663934443; bh=WopEYyZyp7OLlLvP/e4SSX5wjuoeVcD4xwtk32bo8sY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jF6O2IJ9t4CrKgF0f32BQDzoWtK+Y+sPGN1MuqqMN9sZ1ZmakAv4I3o3vTbo+EFhW xFCEmFPZwS46HKZMPprYbBak0jPAde2RUtkmbuQrXy1CYFNvdqtHGahgJon5Q+Tc2o Omc5CMYHwauKv4B7D2wWxZvtbNJFbD/gi6ZA806o= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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