RFR: 8274400: HotSpot Style Guide should permit use of alignof [v3]
Kim Barrett
kbarrett at openjdk.org
Fri Dec 30 02:36:51 UTC 2022
On Wed, 28 Dec 2022 11:02:06 GMT, Julian Waters <jwaters at openjdk.org> wrote:
>> The alignof operator was added by C++11. It returns the alignment for the given type. Various metaprogramming usages exist, in particular when using std::aligned_storage. Use of this operator should be permitted in HotSpot code.
>
> Julian Waters has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
>
> - Make section more brief
> - Merge remote-tracking branch 'upstream/master' into alignof
> - More Descriptive Version
> - Merge remote-tracking branch 'upstream/master' into alignof
> - HotSpot Style Guide should permit use of alignof
Changes requested by kbarrett (Reviewer).
doc/hotspot-style.md line 706:
> 704: alternative to `std::alignment_of<>`. The template precedes the operator
> 705: in the language, so `alignof` should be preferred to `std::alignment_of<>`
> 706: if possible.
`alignof` doesn't "check" anything. And this is still overly verbose. Keep it
simple. I was going to suggest using this:
"`alignof`(ref...) is permitted. Use `alignof` instead of `std::alignment_of<>`."
But I think better is to add `alignof` to the "### Additional Permitted
Features" list, and change the place where inclusion of `<type_traits>` is
discussed, adding a restriction against using `std::alignment_of<>`. There one
can justify the restriction by noting the trait class preceded the operator
and provides the same functionality. We're probably going to want additional
restrictions for `<type_traits>` because of
https://bugs.openjdk.org/browse/JDK-8298399.
So edit that section like so:
* `#include <type_traits>` with restrictions (see below).
...
Some definitions from `<type_traits>` should not be used.
* `std::alignment_of<>` has been superseded by `alignof`, which should be used instead.
-------------
PR: https://git.openjdk.org/jdk/pull/11761
More information about the hotspot-dev
mailing list