|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4311" status="New"> |
| 5 | +<title>Can `std::pmr::polymorphic_allocator::construct` just call `std::uninitialized_construct_using_allocator`?</title> |
| 6 | +<section> |
| 7 | +<sref ref="[mem.poly.allocator.mem]"/> |
| 8 | +</section> |
| 9 | +<submitter>Jiang An</submitter> |
| 10 | +<date>06 Aug 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +This is closely related to LWG <iref ref="3901"/> but only affects arguably pathological cases. |
| 16 | +<p/> |
| 17 | +Uses-allocator construction for <i>cv</i>-qualified types needs to be well-formed, but it's |
| 18 | +questionable to require `polymorphic_allocator::construct` to support constructing objects via |
| 19 | +pointer to a <i>cv</i>-qualified type. LWG <iref ref="3870"/> banned such placement construction |
| 20 | +for `std::construct_at`, which is depended by `uninitialized_construct_using_allocator`. |
| 21 | +<p/> |
| 22 | +As a result, it seems non-conforming to just use `uninitialized_construct_using_allocator` in |
| 23 | +`polymorphic_allocator::construct` since C++20, because the latter is still required to handle |
| 24 | +<i>cv</i>-qualified target types. If the status quo is considered unintended and needed to be fixed, |
| 25 | +perhaps we can just respecify `polymorphic_allocator::construct` to use |
| 26 | +`uninitialized_construct_using_allocator`. |
| 27 | +</p> |
| 28 | +</discussion> |
| 29 | + |
| 30 | +<resolution> |
| 31 | +<p> |
| 32 | +This wording is relative to this |
| 33 | +<a href="https://github.com/cplusplus/draft/actions/runs/16749320058/artifacts/3690555293">CD preview draft</a>. |
| 34 | +</p> |
| 35 | + |
| 36 | +<blockquote class="note"> |
| 37 | +<p> |
| 38 | +[<i>Drafting note</i>: The <i>Mandates</i>: element allows implementations not to add constraints even if |
| 39 | +`uninitialized_construct_using_allocator` is constrained in the future. The <i>Throws</i>: element is made |
| 40 | +redundant by "<i>Effects</i>: Equivalent to", and it's already wrong because the exception can be thrown |
| 41 | +by a conversion function.] |
| 42 | +</p> |
| 43 | +</blockquote> |
| 44 | + |
| 45 | +<ol> |
| 46 | + |
| 47 | +<li><p>Modify <sref ref="[mem.poly.allocator.mem]"/> as indicated:</p> |
| 48 | + |
| 49 | +<blockquote> |
| 50 | +<pre> |
| 51 | +template<class T, class... Args> |
| 52 | + void construct(T* p, Args&&... args); |
| 53 | +</pre> |
| 54 | +<blockquote> |
| 55 | +<p> |
| 56 | +-14- <i>Mandates</i>: <del>Uses-allocator construction of `T` with allocator `*this` (see |
| 57 | +<sref ref="[allocator.uses.construction]"/>) and constructor arguments |
| 58 | +<tt>std::forward<Args>(args)...</tt></del><ins><tt>uninitialized_construct_using_allocator(p, |
| 59 | +*this, std::forward<Args>(args)...)</tt></ins> is well-formed. |
| 60 | +<p/> |
| 61 | +-15- <i>Effects</i>: <del>Constructs a `T` object in the storage whose address is represented by |
| 62 | +`p` by uses-allocator construction with allocator `*this` and constructor arguments |
| 63 | +<tt>std::forward<Args>(args)...</tt>.</del><ins>Equivalent to:</ins> |
| 64 | +</p> |
| 65 | +<blockquote><pre> |
| 66 | +<ins>uninitialized_construct_using_allocator(p, *this, std::forward<Args>(args)...);</ins> |
| 67 | +</pre></blockquote> |
| 68 | +<p> |
| 69 | +<del>-16- <i>Throws</i>: Nothing unless the constructor for `T` throws.</del> |
| 70 | +</p> |
| 71 | +</blockquote> |
| 72 | +</blockquote> |
| 73 | + |
| 74 | +</li> |
| 75 | + |
| 76 | +</ol> |
| 77 | +</resolution> |
| 78 | + |
| 79 | +</issue> |
0 commit comments