RFR: 8274400: HotSpot Style Guide should permit use of alignof [v4]

Julian Waters jwaters at openjdk.org
Wed Jan 4 13:01:52 UTC 2023


On Sun, 1 Jan 2023 02:15:56 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Something like this perhaps?
>> 
>> - Prefer `alignof` ([n2341](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf)) to `std::alignment_of<>`. The template has been superseded by the newer operator.
>
>> I'm not sure if it's a good idea to entirely forbid `std::alignment_of<>`?
> 
> I disagree.
> 
>> While `alignof` should be used over it most of the time, I'm somewhat certain
>> it and it's other counterpart from C++17 (may) have certain differences from
>> `alignof` in newer versions of the language ...
> 
> `std::alignment_of<T>::value` is defined as `alignof(T)` in every version of
> the standard. The C++17 addition of `std::alignment_of_v<T>` is just
> abbreviated syntactic sugar, and is still more verbose than using `alignof`. I
> see no other changes between versions of the standard, and would be surprised
> if any were to come in the future.
> 
>> ... (especially when used with templates and in metaprogramming contexts) ...
> 
> `std::alignment_of<>` could be used in advanced metaprogramming contexts
> involving higher order metafunctions. We don't do that sort of thing much at
> all in HotSpot. If someone finds a place where `std::alignment_of<>` might be
> better, we can revisit its status.
> 
>> (Similar to how nullptr vs NULL is discussed in the Style Guide).
> 
> nullptr vs NULL is a very different situation. New code and substantial
> changes should use nullptr. But there is a large body of existing code using
> NULL. When making a small modification to such code one might choose to
> continue using NULL to be consistent with surrounding code. And one might
> choose to keep such a change separate from a NULL => nullptr change in that
> surrounding code. There are no current uses of `std::alignment_of<>` to be
> consistent with.

Alright, I'm convinced

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

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


More information about the hotspot-dev mailing list