https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124404
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |jakub at gcc dot gnu.org
Resolution|--- |INVALID
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is how it is meant to work.
The argument of the builtin is something on which one can call the .data() and
.size() methods etc.
std::string is not that.
The indended use of the built is
namespace std
{
#if __has_builtin(__builtin_constexpr_diag)
struct _S_constexpr_tag_str {
private:
string_view _M_str;
public:
template <class _Tp>
requires convertible_to<const _Tp&, string_view>
consteval _S_constexpr_tag_str(const _Tp& __s) : _M_str(__s) {}
friend constexpr void constexpr_print_str(_S_constexpr_tag_str __tag,
string_view) noexcept;
friend constexpr void constexpr_print_str(_S_constexpr_tag_str __tag,
u8string_view) noexcept;
friend constexpr void constexpr_warning_str(_S_constexpr_tag_str,
string_view) noexcept;
friend constexpr void constexpr_warning_str(_S_constexpr_tag_str,
u8string_view) noexcept;
friend constexpr void constexpr_error_str(_S_constexpr_tag_str,
string_view) noexcept;
friend constexpr void constexpr_error_str(_S_constexpr_tag_str,
u8string_view) noexcept;
};
constexpr void constexpr_print_str(string_view __msg) noexcept
{ return __builtin_constexpr_diag(16, "", __msg); }
constexpr void constexpr_print_str(u8string_view __msg) noexcept
{ return __builtin_constexpr_diag(16, "", __msg); }
constexpr void constexpr_print_str(_S_constexpr_tag_str __tag,
string_view __msg) noexcept
{ return __builtin_constexpr_diag(16, __tag._M_str, __msg); }
constexpr void constexpr_print_str(_S_constexpr_tag_str __tag,
u8string_view __msg) noexcept
{ return __builtin_constexpr_diag(16, __tag._M_str, __msg); }
constexpr void constexpr_warning_str(_S_constexpr_tag_str __tag,
string_view __msg) noexcept
{ return __builtin_constexpr_diag(17, __tag._M_str, __msg); }
constexpr void constexpr_warning_str(_S_constexpr_tag_str __tag,
u8string_view __msg) noexcept
{ return __builtin_constexpr_diag(17, __tag._M_str, __msg); }
constexpr void constexpr_error_str(_S_constexpr_tag_str __tag,
string_view __msg) noexcept
{ return __builtin_constexpr_diag(18, __tag._M_str, __msg); }
constexpr void constexpr_error_str(_S_constexpr_tag_str __tag,
u8string_view __msg) noexcept
{ return __builtin_constexpr_diag(18, __tag._M_str, __msg); }
#endif
}
but that is not in the library because it hasn't been standardized (yet).
So, if you use it directly, you need to use it on string_view/u8_string_view or
something compatible or construct a string_view etc. from the std::string.