RFR: 8314488: Compiling the JDK with C++17
Kim Barrett
kbarrett at openjdk.org
Sat Aug 16 23:47:10 UTC 2025
On Fri, 15 Aug 2025 13:48:20 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
> > Would this give us size_t literal suffixes? Something like "0uz"?
>
> That's C++23.
On the other hand, I don't know of anything that prevents us from defining
"_zu" as user-defined literal syntax while we wait for C++23. (Dropping the
underscore puts us in reserved syntax land, and likely requires suppressing
warnings at least.)
And I'm certainly tired of casting literals to size_t.
The style guide currently says "User-defined literals should not be added
casually, but only through a proposal to add a specific UDL." So propose that
syntax, implemented by adding something like the following in
globalDefinitions.hpp:
constexpr operator ""_zu(unsigned long long int x) {
// Probably only relevant for 32bit platforms.
assert(x <= std::numeric_limits<size_t>::max(), "invalid size_t literal");
return static_cast<size_t>(x);
}
The C++23 literal syntax supports different cases and different orders for "u"
and "z". Probably don't bother with that for ours.
We should be able to provide a "_z" suffix to support ssize_t literals, but
I'm failing to figure out the details of that today. (It' pretty late in my
day, so I'm assuming it's possible and I'm just too sleepy to figure it out.)
It's less important anyway.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25992#issuecomment-3193969292
More information about the hotspot-dev
mailing list