mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-12-24 11:35:31 +08:00
libstdc++: Fix tests for constexpr std::string
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.
This commit is contained in:
parent
395848255c
commit
73e4d9f175
@ -3546,8 +3546,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
|
|||||||
* greater than, or incomparable with `__rhs`.
|
* greater than, or incomparable with `__rhs`.
|
||||||
*/
|
*/
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
_GLIBCXX20_CONSTEXPR
|
constexpr auto
|
||||||
inline auto
|
|
||||||
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
|
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
|
||||||
const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept
|
const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept
|
||||||
-> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
|
-> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
|
||||||
@ -3561,8 +3560,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
|
|||||||
* greater than, or incomparable with `__rhs`.
|
* greater than, or incomparable with `__rhs`.
|
||||||
*/
|
*/
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
_GLIBCXX20_CONSTEXPR
|
constexpr auto
|
||||||
inline auto
|
|
||||||
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
|
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
|
||||||
const _CharT* __rhs) noexcept
|
const _CharT* __rhs) noexcept
|
||||||
-> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
|
-> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// { dg-options "-std=gnu++20" }
|
// { dg-options "-std=gnu++20" }
|
||||||
// { dg-do compile { target c++20 } }
|
// { dg-do compile { target c++20 } }
|
||||||
|
// { dg-require-effective-target cxx11-abi }
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
@ -26,6 +26,12 @@
|
|||||||
# define NOTHROW
|
# define NOTHROW
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
# define CONSTEXPR constexpr
|
||||||
|
#else
|
||||||
|
# define CONSTEXPR
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
// lib.char.traits, character traits:
|
// lib.char.traits, character traits:
|
||||||
template<class charT>
|
template<class charT>
|
||||||
@ -40,33 +46,52 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
|||||||
_GLIBCXX_END_NAMESPACE_CXX11
|
_GLIBCXX_END_NAMESPACE_CXX11
|
||||||
|
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
|
CONSTEXPR
|
||||||
basic_string<charT,traits,Allocator>
|
basic_string<charT,traits,Allocator>
|
||||||
operator+(const basic_string<charT,traits,Allocator>& lhs,
|
operator+(const basic_string<charT,traits,Allocator>& lhs,
|
||||||
const basic_string<charT,traits,Allocator>& rhs);
|
const basic_string<charT,traits,Allocator>& rhs);
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
|
CONSTEXPR
|
||||||
basic_string<charT,traits,Allocator>
|
basic_string<charT,traits,Allocator>
|
||||||
operator+(const charT* lhs,
|
operator+(const charT* lhs,
|
||||||
const basic_string<charT,traits,Allocator>& rhs);
|
const basic_string<charT,traits,Allocator>& rhs);
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
|
CONSTEXPR
|
||||||
basic_string<charT,traits,Allocator>
|
basic_string<charT,traits,Allocator>
|
||||||
operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
|
operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
|
CONSTEXPR
|
||||||
basic_string<charT,traits,Allocator>
|
basic_string<charT,traits,Allocator>
|
||||||
operator+(const basic_string<charT,traits,Allocator>& lhs,
|
operator+(const basic_string<charT,traits,Allocator>& lhs,
|
||||||
const charT* rhs);
|
const charT* rhs);
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
|
CONSTEXPR
|
||||||
basic_string<charT,traits,Allocator>
|
basic_string<charT,traits,Allocator>
|
||||||
operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
|
operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
|
||||||
|
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
|
CONSTEXPR
|
||||||
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
||||||
const basic_string<charT,traits,Allocator>& rhs) NOTHROW;
|
const basic_string<charT,traits,Allocator>& rhs) NOTHROW;
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
bool operator==(const charT* lhs,
|
CONSTEXPR
|
||||||
const basic_string<charT,traits,Allocator>& rhs);
|
|
||||||
template<class charT, class traits, class Allocator>
|
|
||||||
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
||||||
const charT* rhs);
|
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>
|
template<class charT, class traits, class Allocator>
|
||||||
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
||||||
const basic_string<charT,traits,Allocator>& rhs) NOTHROW;
|
const basic_string<charT,traits,Allocator>& rhs) NOTHROW;
|
||||||
@ -114,9 +139,11 @@ _GLIBCXX_END_NAMESPACE_CXX11
|
|||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
bool operator>=(const charT* lhs,
|
bool operator>=(const charT* lhs,
|
||||||
const basic_string<charT,traits,Allocator>& rhs);
|
const basic_string<charT,traits,Allocator>& rhs);
|
||||||
|
#endif
|
||||||
|
|
||||||
// lib.string.special:
|
// lib.string.special:
|
||||||
template<class charT, class traits, class Allocator>
|
template<class charT, class traits, class Allocator>
|
||||||
|
CONSTEXPR
|
||||||
void swap(basic_string<charT,traits,Allocator>& lhs,
|
void swap(basic_string<charT,traits,Allocator>& lhs,
|
||||||
basic_string<charT,traits,Allocator>& rhs)
|
basic_string<charT,traits,Allocator>& rhs)
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
|
Loading…
Reference in New Issue
Block a user