@@ -70,6 +70,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// [format.context], class template basic_format_context
template<typename _Out, typename _CharT> class basic_format_context;
+ // [format.fmt.string], class template basic_format_string
+ template<typename _CharT, typename... _Args> struct basic_format_string;
+
/// @cond undocumented
namespace __format
{
@@ -83,7 +86,20 @@ namespace __format
using __format_context = basic_format_context<_Sink_iter<_CharT>, _CharT>;
template<typename _CharT>
- struct _Runtime_format_string { basic_string_view<_CharT> _M_str; };
+ struct _Runtime_format_string
+ {
+ [[__gnu__::__always_inline__]]
+ _Runtime_format_string(basic_string_view<_CharT> __s) noexcept
+ : _M_str(__s) { }
+
+ _Runtime_format_string(const _Runtime_format_string&) = delete;
+ void operator=(const _Runtime_format_string&) = delete;
+
+ private:
+ basic_string_view<_CharT> _M_str;
+
+ template<typename, typename...> friend struct std::basic_format_string;
+ };
} // namespace __format
/// @endcond
@@ -104,8 +120,6 @@ namespace __format
template<typename _Context>
class basic_format_arg;
- // [format.fmt.string], class template basic_format_string
-
/** A compile-time checked format string for the specified argument types.
*
* @since C++23 but available as an extension in C++20.
@@ -119,7 +133,7 @@ namespace __format
basic_format_string(const _Tp& __s);
[[__gnu__::__always_inline__]]
- basic_format_string(__format::_Runtime_format_string<_CharT>&& __s)
+ basic_format_string(__format::_Runtime_format_string<_CharT> __s) noexcept
: _M_str(__s._M_str)
{ }
@@ -144,14 +158,14 @@ namespace __format
#if __cplusplus > 202302L
[[__gnu__::__always_inline__]]
inline __format::_Runtime_format_string<char>
- runtime_format(string_view __fmt)
- { return {__fmt}; }
+ runtime_format(string_view __fmt) noexcept
+ { return __fmt; }
#ifdef _GLIBCXX_USE_WCHAR_T
[[__gnu__::__always_inline__]]
inline __format::_Runtime_format_string<wchar_t>
- runtime_format(wstring_view __fmt)
- { return {__fmt}; }
+ runtime_format(wstring_view __fmt) noexcept
+ { return __fmt; }
#endif
#endif // C++26
@@ -3652,12 +3666,9 @@ namespace __format
friend std::basic_format_args<_Context>;
template<typename _Ctx, typename... _Argz>
- friend auto
+ friend auto std::
#if _GLIBCXX_INLINE_VERSION
- // Needed for PR c++/59526
- std::__8::
-#else
- std::
+ __8:: // Needed for PR c++/59256
#endif
make_format_args(_Argz&...) noexcept;
@@ -29,6 +29,17 @@ test_internal_api()
VERIFY( s == "0x315" );
}
+static_assert( noexcept(std::format_string<>(std::runtime_format(""))) );
+static_assert( noexcept(std::wformat_string<>(std::runtime_format(L""))) );
+static_assert( noexcept(std::format_string<int>(std::runtime_format(""))) );
+static_assert( noexcept(std::wformat_string<char>(std::runtime_format(L""))) );
+// A format string can be constructed from the result of std::runtime_format
+// using copy elision, but cannot be constructed from an xvalue.
+static_assert( !std::is_constructible_v<std::format_string<>,
+ decltype(std::runtime_format(""))&&> );
+static_assert( !std::is_constructible_v<std::wformat_string<>,
+ decltype(std::runtime_format(L""))&&> );
+
int main()
{
test_char();