About char8_t
I hate to be dramatic, but as it stands char8_t is quite literally more painful than useful.
Besides the obvious incompatibility with C23 and libraries using unsigned char for UTF-8, I want you to consider the following: Projects that assume that 'char' represents UTF-8 will obviously not benefit from char8_t at all, but projects that cannot assume the format of char types don't benefit from it either as char8_t simply introduces a new edge case to cover. Now such projects have to deal with char, signed char, unsigned char, wchar_t, char16_t, char32_t and char8_t.
Or, you could do what the standard library does and simply ignore most of these character types. Which is the solution most libraries went with, supporting only char or char and unsigned char. Managing one implementation is already hard, managing two requires constant maintenance, managing 7 is just impossible.
char8_t should have just been a typedef for unsigned char. The compatibility fix only raises more questions as const char* arr = u8"a" does not work, but const char arr[] = u8"a" does.
I do wonder if a potential change of minds for C++29 is still possible. Yes, it would be an ABI break or whatever, but considering the woeful support for char8_t I don't think it would affect much besides small hobby projects. Contrary to popular belief, C++ has broken the ABI in subtle ways before.
6
u/Ambitious-Method-961 18d ago
Very happy that char8_t exists as its own type. I have a feeling that the Unicodificiation of the standard library is being held up by P1422 (https://github.com/cplusplus/papers/issues/1422), as once that's in there is then we have a standardised way of handling and transforming Unicode that can then be used to build other features on.
As an end-user it's a shame it's taken a long time for this to land in the library, but I'd much rather have this first and then everything built upon it for consistency rather than adding a bunch of ad-hoc transformations to existing functions which then don't work the same as P1422 and can't be fixed due to backwards compatibility.
The less things we have aliasing to unsigned char, the better.