Integrated: 8300080: offset_of for GCC/Clang exhibits undefined behavior and is not always a compile-time constant

Kim Barrett kbarrett at openjdk.org
Thu Sep 4 05:44:51 UTC 2025


On Tue, 2 Sep 2025 23:25:43 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

> Please review this change to offset_of to just use offsetof as it's
> implementation. The rationale for this is
> 
> (1) Despite being UB for some cases that we use (through C++14), none of the
> compilers we use actually treat it as such, other than some compilers issuing
> warnings. (Surprisingly, the UB doesn't appear to disable constexpr evaluation?)
> 
> (2) C++17 changed it to be conditionally defined in those formerly UB cases,
> and we'll be switching over to C++17 soon (JDK-8314488).
> 
> Until we make the switch to C++17 we need to suppress warnings from some
> compilers for such uses. We can remove that warning suppression later.
> 
> See the JBS issue for more discussion.
> 
> Testing: mach5 tier1

This pull request has now been integrated.

Changeset: 62bc7b7c
Author:    Kim Barrett <kbarrett at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/62bc7b7c4247a62c23ea93cd960c3c0434925c49
Stats:     26 lines in 4 files changed: 5 ins; 20 del; 1 mod

8300080: offset_of for GCC/Clang exhibits undefined behavior and is not always a compile-time constant

Reviewed-by: stefank, jsjolen

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

PR: https://git.openjdk.org/jdk/pull/27061


More information about the hotspot-dev mailing list