From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id B6BE4385742D; Fri, 23 Sep 2022 11:58:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6BE4385742D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663934303; bh=mULaXTES9MJ1R1Gzxo+beTrnnOpo/E61gTfvM/t+A7U=; h=From:To:Subject:Date:From; b=NHK+TPCjkgUIQHTqyG+F6RJo/xYDQPZuqL+It3bzT0wUZNTe7fXy43lbYvOxGzCbM ADfR0z2Ls5X9J+gO8ropcgXLE2SXZHRGOUIwc13dLFBjD4Su7C0YqeEifJhGoeyl/Z QPCICVv/Y+y44d/02Z6r3FFUtr7VOMb/17RQRblI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2815] libstdc++: Enable constexpr std::bitset for debug mode X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: ffb03fa12850df3a4f53435d5f20ff122c83732a X-Git-Newrev: 4ceb5bc42d9d703bac5c98b94c639ef9438aaede Message-Id: <20220923115823.B6BE4385742D@sourceware.org> Date: Fri, 23 Sep 2022 11:58:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4ceb5bc42d9d703bac5c98b94c639ef9438aaede commit r13-2815-g4ceb5bc42d9d703bac5c98b94c639ef9438aaede Author: Jonathan Wakely Date: Fri Sep 23 10:12:09 2022 +0100 libstdc++: Enable constexpr std::bitset for debug mode 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. Diff: --- libstdc++-v3/include/debug/bitset | 43 +++++++++++++++++++--- .../testsuite/20_util/bitset/access/constexpr.cc | 2 + .../20_util/bitset/cons/constexpr_c++23.cc | 2 + .../testsuite/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