RFR: 8255082: HotSpot Style Guide should permit noexcept [v3]
Vladimir Kozlov
kvn at openjdk.org
Fri Jun 20 16:46:28 UTC 2025
On Fri, 20 Jun 2025 15:56:42 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> doc/hotspot-style.md line 1118:
>>
>>> 1116: failure must be declared `noexcept`.
>>> 1117: * All other uses of `noexcept` exception specifications are forbidden.
>>> 1118: * `noexcept` expressions are forbidden.
>>
>> "argument-less form of `noexcept` are permitted" vs "`noexcept` expressions are forbidden". So what we should use? `noexcept()`? The example would be nice.
>
> The standard allows `noexcept` to be used in two different contexts. It can be
> used in a function's exception specification. It can instead be used in an
> ordinary expression. In either case it takes one argument expression, but what
> form that can take and how it is interpreted is quite different, depending on
> which of those contexts applies.
>
> Used in an exception specification, the argument must be a constant
> expression. So one can write a conditional exception specification, indicating
> that a function is non-throwing if the argument is true, and potentially
> throwing if false. One use-case for this is a generic container, where some
> operations may only be noexept if certain operations of the element type are
> noexcept. In this context, `noexcept` (without arguments) is equivalent to
> `noexcept(true)`, and also to the deprecated `throw()` (with no arguments). At
> this time I think we don't ever need arguments, and the no-arg abbreviation is
> sufficient. That might change if we move toward using standard library
> facilities (particularly containers), or make our own more like those in the
> standard.
>
> Used as an expression, the argument is an unevaluated expression (similar to
> some uses of sizeof and alignof). The result of the `noexcept` expression is a
> bool constant, and is true if the expression never throws (based on examining
> exception specifications of functions called in the expression), false
> otherwise. There isn't an abbreviated expression form without arguments, as
> that doesn't make sense. At this time I think we don't need `noexcept`
> expressions, and might never need them.
>
> (Note that the argument expression for a `noexcept` exception specification
> can include `noexcept` expressions. But since we're not currently allowing
> either, that doesn't matter.)
Got it. No `noexcept` in regular expressions. No `noexcept(foo())`.
But we can use `foo() noexcept(true);` which is equivalent to ``foo() noexcept;`
Do we have case for `noexcept(false);` in VM?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25574#discussion_r2159362992
More information about the hotspot-dev
mailing list