|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4290" status="New"> |
| 5 | +<title>Missing <i>Mandates</i> clauses on `is_sufficiently_aligned`</title> |
| 6 | +<section> |
| 7 | +<sref ref="[ptr.align]"/> |
| 8 | +</section> |
| 9 | +<submitter>Damien Lebrun-Grandie</submitter> |
| 10 | +<date>03 Jul 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +`is_sufficiently_aligned` should mandate that the alignment template argument is a power of two |
| 16 | +and that it is greater equal to the byte alignment of its type template argument. |
| 17 | +<p/> |
| 18 | +In <sref ref="[ptr.align]"/> `is_sufficiently_aligned` has no <i>Mandates</i> element. It is an |
| 19 | +oversight that we realized when implementing <paper num="P2897R7"/> into libc++ |
| 20 | +(in <a href="https://github.com/llvm/llvm-project/pull/122603">https://github.com/llvm/llvm-project/pull/122603</a>). |
| 21 | +The function template was originally proposed as a static member function of the `aligned_accessor` |
| 22 | +class template which has these two <i>Mandates</i> clauses and therefore applied |
| 23 | +(see <sref ref="[mdspan.accessor.aligned.overview]"/> p1). It revision <paper num="P2897R4"/>, |
| 24 | +`is_sufficiently_aligned` was moved out the class template definition to become the free function |
| 25 | + memory helper that was voted into C++26 but the <i>Mandates</i> were lost in the process. |
| 26 | +<p/> |
| 27 | +We propose to correct that oversight and reintroduce the following <i>Mandates</i> clauses right above |
| 28 | +<sref ref="[ptr.align]"/> p10. |
| 29 | +</p> |
| 30 | +</discussion> |
| 31 | + |
| 32 | +<resolution> |
| 33 | +<p> |
| 34 | +This wording is relative to <paper num="N5008"/>. |
| 35 | +</p> |
| 36 | + |
| 37 | +<ol> |
| 38 | + |
| 39 | +<li><p>Modify <sref ref="[ptr.align]"/> as indicated:</p> |
| 40 | + |
| 41 | +<blockquote> |
| 42 | +<pre> |
| 43 | +template<size_t Alignment, class T> |
| 44 | + bool is_sufficiently_aligned(T* ptr); |
| 45 | +</pre> |
| 46 | +<blockquote> |
| 47 | +<p> |
| 48 | +<ins>-?- <i>Mandates</i>:</ins> |
| 49 | +</p> |
| 50 | +<ol style="list-style-type: none"> |
| 51 | +<li><p><ins>(?.1) — `Alignment` is a power of two, and</ins></p></li> |
| 52 | +<li><p><ins>(?.2) — <tt>Alignment >= alignof(T)</tt> is `true`.</ins></p></li> |
| 53 | +</ol> |
| 54 | +<p> |
| 55 | +-10- <i>Preconditions</i>: `p` points to an object `X` of a type similar |
| 56 | +(<sref ref="[conv.qual]"/>) to `T`. |
| 57 | +<p/> |
| 58 | +-11- <i>Returns</i>: `true` if `X` has alignment at least `Alignment`, otherwise `false`. |
| 59 | +<p/> |
| 60 | +-12- <i>Throws</i>: Nothing. |
| 61 | +</p> |
| 62 | +</blockquote> |
| 63 | +</blockquote> |
| 64 | +</li> |
| 65 | + |
| 66 | +</ol> |
| 67 | +</resolution> |
| 68 | + |
| 69 | +</issue> |
0 commit comments