RFR: 8319242: HotSpot Style Guide should discourage non-local variables with non-trivial initialization or destruction [v2]

David Holmes dholmes at openjdk.org
Tue Jun 17 12:54:30 UTC 2025


On Tue, 17 Jun 2025 08:36:29 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> doc/hotspot-style.md line 778:
>> 
>>> 776: [C++14 3.6.2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf)).
>>> 777: should be avoided, unless an implementation is permitted to perform the
>>> 778: initialization as a static initialization. The order in which dynamic
>> 
>> What does "an implementation" refer to here? The C++ compiler? If so how could we permit this unless all supported "implementations" are guaranteed to permit it?
>
> Yes, "an implementation" is the C++ compiler.
> 
> The restrictions on static initialization are significantly more stringent
> than we want to require. The restrictions on dynamic initialization => static
> initialization seem like pretty much what we would want, e.g. (roughly)
> doesn't affect other initializations by assignments to global variables, and
> doesn't depend on other initializations that are not required to be ordered
> before it. So even if the implementation doesn't perform the initialization
> statically, things should be okay. I won't guarantee there's no possibility
> for problems, as there may be edge cases or implementation bugs, but this
> seems pretty safe to me. I think the most likely way to fail is for us to
> not recognize an unordered dependency in our code. Keeping dynamic
> initializations fairly simple is probably the best way to avoid that.

Sorry but I'm having trouble understanding how somehow could evaluate whether a dynamic initialization is okay based on the current statement.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25812#discussion_r2152196378


More information about the hotspot-dev mailing list