Title
std::align requirements overly strict
Status
c++17
Section
[ptr.align]
Submitter
Peter Dimov

Created on 2014-03-30.00:00:00 last changed 81 months ago

Messages

Date: 2014-06-16.23:38:27

Proposed resolution:

This wording is relative to N3936.

  1. Edit [ptr.align] p2 as indicated:

    void* align(std::size_t alignment, std::size_t size,
      void*& ptr, std::size_t& space);
    

    -1- […]

    -2- Requires:

    • alignment shall be a fundamental alignment value or an extended alignment value supported by the implementation in this contextpower of two

Date: 2014-06-16.00:00:00

[ 2014-06-16 Rapperswil ]

Move to Ready

Date: 2014-03-30.00:00:00

std::align requires that its alignment argument shall be "a fundamental alignment value or an extended alignment value supported by the implementation in this context".

This requirement is overly strict. There are use cases that require a buffer aligned at values that are not tied to the C++ implementation, such as page size, cache line size, sector size. These come from the hardware or the OS and are generally not known until run time. The implementation of std::align does not depend on the requirement that alignment be a fundamental or an extended alignment value; any power of two would be handled the same way.

In addition, it is not possible for the user to even determine whether a value is "a fundamental alignment value or an extended alignment value supported by the implementation in this context". One would expect values coming from alignof to be fine, but I'm not sure whether even that is guaranteed in the presence of alignas.

Therefore, I propose that

Requires:

  • alignment shall be a fundamental alignment value or an extended alignment value supported by the implementation in this context

be changed to

Requires:

  • alignment shall be a power of two

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2014-11-08 19:44:42adminsetstatus: voting -> wp
2014-11-04 10:26:50adminsetstatus: ready -> voting
2014-06-16 23:38:27adminsetmessages: + msg7050
2014-06-16 23:38:27adminsetstatus: new -> ready
2014-03-31 19:39:38adminsetmessages: + msg6933
2014-03-30 00:00:00admincreate