[RFC] libstdc++: fix declaration and definition mismatch for _GLIBCXX20_CONSTEXPR
Alexey Lapshin
alexey.lapshin@espressif.com
Mon May 19 10:43:39 GMT 2025
fix compile errors appeared for test program:
// g++ test.cpp -D_GLIBCXX20_CONSTEXPR="__attribute__((cold))" -std=gnu++20
#include <string>
int main() { return 0; }
---
libstdc++-v3/include/bits/basic_string.h | 11 +++++----
libstdc++-v3/include/bits/basic_string.tcc | 27 ++++++++--------------
2 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index c90bd099b63..a76402bcb05 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -1257,11 +1257,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
* @since C++23
*/
template<typename _Operation>
- constexpr void
+ _GLIBCXX20_CONSTEXPR void
resize_and_overwrite(size_type __n, _Operation __op);
-#endif
-#if __cplusplus >= 201103L
+ /// Non-standard version of resize_and_overwrite for backward compatibility.
+ template<typename _Operation>
+ constexpr void
+ __resize_and_overwrite(size_type __n, _Operation __op);
+#elif __cplusplus >= 201103L
/// Non-standard version of resize_and_overwrite for C++11 and above.
template<typename _Operation>
_GLIBCXX20_CONSTEXPR void
@@ -4809,7 +4812,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
}
}
-#if __glibcxx_constexpr_string >= 201907L
+#if __glibcxx_constexpr_string >= 202002L
constexpr
#endif
inline wstring
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc
index bca55bc5658..315981d0437 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -646,13 +646,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif // _GLIBCXX_USE_CXX11_ABI
-#if __glibcxx_constexpr_string >= 201907L
-# define _GLIBCXX_STRING_CONSTEXPR constexpr
-#else
-# define _GLIBCXX_STRING_CONSTEXPR
-#endif
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find(const _CharT* __s, size_type __pos, size_type __n) const
@@ -689,7 +684,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
@@ -708,7 +703,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
rfind(const _CharT* __s, size_type __pos, size_type __n) const
@@ -731,7 +726,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
rfind(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
@@ -749,7 +744,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
@@ -766,7 +761,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
@@ -789,7 +784,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
@@ -803,7 +798,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_first_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
@@ -815,7 +810,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
@@ -838,7 +833,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _CharT, typename _Traits, typename _Alloc>
- _GLIBCXX_STRING_CONSTEXPR
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_last_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
@@ -858,8 +853,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return npos;
}
-#undef _GLIBCXX_STRING_CONSTEXPR
-
// 21.3.7.9 basic_string::getline and operators
template<typename _CharT, typename _Traits, typename _Alloc>
basic_istream<_CharT, _Traits>&
--
2.43.0
More information about the Libstdc++
mailing list