This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4290. Missing Mandates clauses on is_sufficiently_aligned

Section: 20.2.5 [ptr.align] Status: New Submitter: Damien Lebrun-Grandie Opened: 2025-07-03 Last modified: 2025-07-06

Priority: Not Prioritized

View other active issues in [ptr.align].

View all other issues in [ptr.align].

View all issues with New status.

Discussion:

is_sufficiently_aligned should mandate that the alignment template argument is a power of two and that it is greater equal to the byte alignment of its type template argument.

In 20.2.5 [ptr.align] is_sufficiently_aligned has no Mandates element. It is an oversight that we realized when implementing P2897R7 into libc++ (in https://github.com/llvm/llvm-project/pull/122603). The function template was originally proposed as a static member function of the aligned_accessor class template which has these two Mandates clauses and therefore applied (see 23.7.3.5.4.1 [mdspan.accessor.aligned.overview] p1). It revision P2897R4, is_sufficiently_aligned was moved out the class template definition to become the free function memory helper that was voted into C++26 but the Mandates were lost in the process.

We propose to correct that oversight and reintroduce the following Mandates clauses right above 20.2.5 [ptr.align] p10.

Proposed resolution:

This wording is relative to N5008.

  1. Modify 20.2.5 [ptr.align] as indicated:

    template<size_t Alignment, class T>
      bool is_sufficiently_aligned(T* ptr);
    

    -?- Mandates:

    1. (?.1) — Alignment is a power of two, and

    2. (?.2) — Alignment >= alignof(T) is true.

    -10- Preconditions: p points to an object X of a type similar (7.3.6 [conv.qual]) to T.

    -11- Returns: true if X has alignment at least Alignment, otherwise false.

    -12- Throws: Nothing.