C++ Logo

sg16

Advanced search

Re: [isocpp-sg16] [P3560] std::meta::exception::what()

From: Corentin Jabot <corentinjabot_at_[hidden]>
Date: Mon, 3 Feb 2025 11:48:26 +0100
This should be u8string_view.

std::meta::exception::what() is an expression, it goes through phase 6, so,
if the literal encoding is not utf-8, it is going to be lossy.
Which is often going to be the case on widows, especially in regions such
as Japan. But anywhere else it is also going to cause issues.
(The message can and will include arbitrary unicode (primarily because of
identifiers) - and an implementation might have to contend to interesting
scenario like cross compiling from linux to zOS (yes, people do that))

The motivation to not do the correct thing here is quite weak as there is
very little use for that string anyway.
It's not likely to be persisted at runtime, so it's not going to be used
with anything in the standard library like iostream, external libraries and
anything else that could motivate a const char* compatibility.

Anything except format.
If we can manage to make format constexpr in the C++26 time frame we can
also make it support utf-8, especially at compile time.

SG-16 previously decided they'd rather have a version of format that takes
a utf8 format string <https://github.com/cplusplus/papers/issues/1917>
rather than adding support for utf-8 argument - let's do that then.
It's not particularly difficult to have enough utf8 support in format to
support the needs of this paper/reflection in general.
And there is no excuse for inducing mojibake in compiler diagnostics.

On Sat, Jan 11, 2025 at 5:50 PM Barry Revzin via SG16 <sg16_at_[hidden]>
wrote:

> Hey all,
>
> Peter and I will have a paper in this upcoming mailing, which can be found
> here (https://isocpp.org/files/papers/P3560R0.html). We're proposing that
> error handling in reflection should use exceptions to be recoverable, now
> that it is possible to have recoverable exceptions during constant
> evaluation.
>
> The part that concerns this list is... what type should
> std::meta::exception::what() return: std::string_view or
> std::u8string_view?
>
>
> - Argument for u8string_view: this is the principled, type system
> correct answer.
> - Argument for string_view: this is the only type for which there is
> absolutely any support whatsoever in the standard library to do anything.
>
> As you all know, this is an area in which I have no expertise (neither
> current nor, if I'm being honest, desired). This discussion will have to go
> to SG16 eventually, so I wanted to just expedite the process.
>
> As we point out, P2996 used to originally use string_view everywhere and
> we changed to provide a dual interface (e.g. identifier_of() and
> u8identifier_of() both exist). That's not really feasible for
> std::meta::exception, we kind of have to pick one.
>
> Thanks,
>
> Barry
> --
> SG16 mailing list
> SG16_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg16
>

Received on 2025-02-03 10:48:46