From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix tests for constexpr std::string
Date: Tue, 16 Nov 2021 22:49:05 +0000 [thread overview]
Message-ID: <20211116224905.3936029-1-jwakely@redhat.com> (raw)
Tested powerpc64le-linux, pushed to trunk.
Some tests fail when run with -D_GLIBCXX_USE_CXX11_ABI or -stdgnu++20.
libstdc++-v3/ChangeLog:
* include/bits/basic_string.h (operator<=>): Use constexpr
unconditionally.
* testsuite/21_strings/basic_string/modifiers/constexpr.cc:
Require cxx11-abit effective target.
* testsuite/21_strings/headers/string/synopsis.cc: Add
conditional constexpr to declarations, and adjust relational
operators for C++20.
---
libstdc++-v3/include/bits/basic_string.h | 6 ++--
.../basic_string/modifiers/constexpr.cc | 1 +
| 33 +++++++++++++++++--
3 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index b6945f1cdfb..0b7d6c0a981 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -3546,8 +3546,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
* greater than, or incomparable with `__rhs`.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX20_CONSTEXPR
- inline auto
+ constexpr auto
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept
-> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
@@ -3561,8 +3560,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
* greater than, or incomparable with `__rhs`.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX20_CONSTEXPR
- inline auto
+ constexpr auto
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const _CharT* __rhs) noexcept
-> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc
index c875a3a19ad..a4627714d9a 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc
@@ -1,5 +1,6 @@
// { dg-options "-std=gnu++20" }
// { dg-do compile { target c++20 } }
+// { dg-require-effective-target cxx11-abi }
#include <string>
#include <testsuite_hooks.h>
--git a/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc b/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc
index f14c4ae831c..f12345ed426 100644
--- a/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc
+++ b/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc
@@ -26,6 +26,12 @@
# define NOTHROW
#endif
+#if __cplusplus >= 202002L
+# define CONSTEXPR constexpr
+#else
+# define CONSTEXPR
+#endif
+
namespace std {
// lib.char.traits, character traits:
template<class charT>
@@ -40,33 +46,52 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_END_NAMESPACE_CXX11
template<class charT, class traits, class Allocator>
+ CONSTEXPR
basic_string<charT,traits,Allocator>
operator+(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
+ CONSTEXPR
basic_string<charT,traits,Allocator>
operator+(const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
+ CONSTEXPR
basic_string<charT,traits,Allocator>
operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
+ CONSTEXPR
basic_string<charT,traits,Allocator>
operator+(const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
+ CONSTEXPR
basic_string<charT,traits,Allocator>
operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
template<class charT, class traits, class Allocator>
+ CONSTEXPR
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs) NOTHROW;
template<class charT, class traits, class Allocator>
- bool operator==(const charT* lhs,
- const basic_string<charT,traits,Allocator>& rhs);
- template<class charT, class traits, class Allocator>
+ CONSTEXPR
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
const charT* rhs);
+
+#if __cpp_lib_three_way_comparison
+ template<class charT, class traits, class Allocator>
+ constexpr
+ bool operator<=>(const basic_string<charT,traits,Allocator>& lhs,
+ const basic_string<charT,traits,Allocator>& rhs) NOTHROW;
+ template<class charT, class traits, class Allocator>
+ constexpr
+ bool operator<=>(const basic_string<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+#else
+ template<class charT, class traits, class Allocator>
+ CONSTEXPR
+ bool operator==(const charT* lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT,traits,Allocator>& rhs) NOTHROW;
@@ -114,9 +139,11 @@ _GLIBCXX_END_NAMESPACE_CXX11
template<class charT, class traits, class Allocator>
bool operator>=(const charT* lhs,
const basic_string<charT,traits,Allocator>& rhs);
+#endif
// lib.string.special:
template<class charT, class traits, class Allocator>
+ CONSTEXPR
void swap(basic_string<charT,traits,Allocator>& lhs,
basic_string<charT,traits,Allocator>& rhs)
#if __cplusplus >= 201103L
--
2.31.1
reply other threads:[~2021-11-16 22:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211116224905.3936029-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).