|
4 | 4 | <meta charset="utf-8" /> |
5 | 5 | <meta name="generator" content="mpark/wg21" /> |
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
7 | | - <meta name="dcterms.date" content="2024-12-16" /> |
| 7 | + <meta name="dcterms.date" content="2025-02-11" /> |
8 | 8 | <title>trivial unions (was std::uninitialized<T>)</title> |
9 | 9 | <style> |
10 | 10 | code{white-space: pre-wrap;} |
|
448 | 448 | td > div.sourceCode { |
449 | 449 | background-color: inherit; |
450 | 450 | } |
| 451 | +td > div > div.sourceCode { |
| 452 | +background-color: inherit; |
| 453 | +} |
451 | 454 | table { |
452 | 455 | border-collapse: collapse; |
453 | 456 | } |
@@ -567,7 +570,7 @@ <h1 class="title" style="text-align:center">trivial |
567 | 570 | </tr> |
568 | 571 | <tr> |
569 | 572 | <td>Date:</td> |
570 | | - <td>2024-12-16</td> |
| 573 | + <td>2025-02-11</td> |
571 | 574 | </tr> |
572 | 575 | <tr> |
573 | 576 | <td style="vertical-align:top">Project:</td> |
@@ -632,10 +635,10 @@ <h1 id="toctitle">Contents</h1> |
632 | 635 | </div> |
633 | 636 | <h1 data-number="1" style="border-bottom:1px solid #cccccc" id="revision-history"><span class="header-section-number">1</span> |
634 | 637 | Revision History<a href="#revision-history" class="self-link"></a></h1> |
635 | | -<p>Since <span class="citation" data-cites="P3074R4">[<a href="https://wg21.link/p3074r4" role="doc-biblioref">P3074R4</a>]</span>, wording changes and adjusted |
| 638 | +<p>Since <span class="citation" data-cites="P3074R4"><a href="https://wg21.link/p3074r4" role="doc-biblioref">[P3074R4]</a></span>, wording changes and adjusted |
636 | 639 | the rule for when a <a href="#constructordestructor-intention-matching">union’s destructor is |
637 | 640 | deleted</a></p> |
638 | | -<p>Since <span class="citation" data-cites="P3074R3">[<a href="https://wg21.link/p3074r3" role="doc-biblioref">P3074R3</a>]</span>, in <a href="https://github.com/cplusplus/papers/issues/1734#issuecomment-2195769496">St. Louis</a>, |
| 641 | +<p>Since <span class="citation" data-cites="P3074R3"><a href="https://wg21.link/p3074r3" role="doc-biblioref">[P3074R3]</a></span>, in <a href="https://github.com/cplusplus/papers/issues/1734#issuecomment-2195769496">St. Louis</a>, |
639 | 642 | EWG had expressed a clear preference for “just make it work”:</p> |
640 | 643 | <table> |
641 | 644 | <thead> |
@@ -699,15 +702,15 @@ <h1 data-number="1" style="border-bottom:1px solid #cccccc" id="revision-history |
699 | 702 | </tbody> |
700 | 703 | </table> |
701 | 704 | <p>So proposing to make it work and adding <a href="#implementation-experience">implementation experience</a>.</p> |
702 | | -<p>Since <span class="citation" data-cites="P3074R2">[<a href="https://wg21.link/p3074r2" role="doc-biblioref">P3074R2</a>]</span>, changed to instead propose a |
| 705 | +<p>Since <span class="citation" data-cites="P3074R2"><a href="https://wg21.link/p3074r2" role="doc-biblioref">[P3074R2]</a></span>, changed to instead propose a |
703 | 706 | language change to unions (with two options) to solve the problems |
704 | 707 | presented</p> |
705 | | -<p>Since <span class="citation" data-cites="P3074R1">[<a href="https://wg21.link/p3074r1" role="doc-biblioref">P3074R1</a>]</span>, the <code class="sourceCode cpp">std<span class="op">::</span>uninitialized<span class="op"><</span>T<span class="op">></span></code> |
| 708 | +<p>Since <span class="citation" data-cites="P3074R1"><a href="https://wg21.link/p3074r1" role="doc-biblioref">[P3074R1]</a></span>, the <code class="sourceCode cpp">std<span class="op">::</span>uninitialized<span class="op"><</span>T<span class="op">></span></code> |
706 | 709 | design was designed in an EWG telecon and the suggestion was made to |
707 | 710 | make this a language feature. Added a section to argue against and |
708 | 711 | re-spelled <code class="sourceCode cpp">std<span class="op">::</span>uninitialized<span class="op"><</span>T<span class="op">></span></code> |
709 | 712 | to be a union instead of a class containing an anonymous union.</p> |
710 | | -<p>Since <span class="citation" data-cites="P3074R0">[<a href="https://wg21.link/p3074r0" role="doc-biblioref">P3074R0</a>]</span>, originally proposed the |
| 713 | +<p>Since <span class="citation" data-cites="P3074R0"><a href="https://wg21.link/p3074r0" role="doc-biblioref">[P3074R0]</a></span>, originally proposed the |
711 | 714 | function <code class="sourceCode cpp">std<span class="op">::</span>start_lifetime<span class="op">(</span>p<span class="op">)</span></code>. |
712 | 715 | R1 adds a new section discussing the <a href="#the-uninitialized-storage-problem">uninitialized storage |
713 | 716 | problem</a>, which motivates a change in design to instead propose <code class="sourceCode cpp">std<span class="op">::</span>uninitialized<span class="op"><</span>T<span class="op">></span></code>.</p> |
@@ -750,10 +753,10 @@ <h1 data-number="2" style="border-bottom:1px solid #cccccc" id="introduction"><s |
750 | 753 | MSVC and EDG accept it and GCC did accept it even up to 13.2, but GCC |
751 | 754 | trunk and Clang reject).</p> |
752 | 755 | <p>Getting this example to work would allow <code class="sourceCode cpp">std<span class="op">::</span>inplace_vector</code> |
753 | | -(<span class="citation" data-cites="P0843R14">[<a href="https://wg21.link/p0843r14" role="doc-biblioref">P0843R14</a>]</span>) to simply work during |
| 756 | +(<span class="citation" data-cites="P0843R14"><a href="https://wg21.link/p0843r14" role="doc-biblioref">[P0843R14]</a></span>) to simply work during |
754 | 757 | <code class="sourceCode cpp"><span class="kw">constexpr</span></code> |
755 | 758 | time for all times (instead of just trivial ones), and was a problem |
756 | | -briefly touched on in <span class="citation" data-cites="P2747R0">[<a href="https://wg21.link/p2747r0" role="doc-biblioref">P2747R0</a>]</span>.</p> |
| 759 | +briefly touched on in <span class="citation" data-cites="P2747R0"><a href="https://wg21.link/p2747r0" role="doc-biblioref">[P2747R0]</a></span>.</p> |
757 | 760 | <h2 data-number="2.1" id="the-uninitialized-storage-problem"><span class="header-section-number">2.1</span> The uninitialized storage |
758 | 761 | problem<a href="#the-uninitialized-storage-problem" class="self-link"></a></h2> |
759 | 762 | <p>A closely related problem to the above is: how do you do |
@@ -957,16 +960,16 @@ <h1 data-number="3" style="border-bottom:1px solid #cccccc" id="design-space"><s |
957 | 960 | <li>provide an explicit function to start lifetime of a union |
958 | 961 | alternative (<code class="sourceCode cpp">std<span class="op">::</span>start_lifetime</code>).</li> |
959 | 962 | </ol> |
960 | | -<p>The first revision of this paper (<span class="citation" data-cites="P3074R0">[<a href="https://wg21.link/p3074r0" role="doc-biblioref">P3074R0</a>]</span>) proposed that last option. |
| 963 | +<p>The first revision of this paper (<span class="citation" data-cites="P3074R0"><a href="https://wg21.link/p3074r0" role="doc-biblioref">[P3074R0]</a></span>) proposed that last option. |
961 | 964 | However, with the addition of the overlapping subobjects problem and the |
962 | 965 | realization that the union solution has overhead compared to the buffer |
963 | 966 | storage solution, it would be more desirable to solve both problems in |
964 | 967 | one go. That is, it’s not enough to just start the lifetime of the |
965 | 968 | alternative, we also want a trivially constructible/destructible |
966 | 969 | solution for uninitialized storage.</p> |
967 | | -<p><span class="citation" data-cites="P3074R1">[<a href="https://wg21.link/p3074r1" role="doc-biblioref">P3074R1</a>]</span> and <span class="citation" data-cites="P3074R2">[<a href="https://wg21.link/p3074r2" role="doc-biblioref">P3074R2</a>]</span> proposed the first solution |
| 970 | +<p><span class="citation" data-cites="P3074R1"><a href="https://wg21.link/p3074r1" role="doc-biblioref">[P3074R1]</a></span> and <span class="citation" data-cites="P3074R2"><a href="https://wg21.link/p3074r2" role="doc-biblioref">[P3074R2]</a></span> proposed the first solution |
968 | 971 | (<code class="sourceCode cpp">std<span class="op">::</span>uninitialized<span class="op"><</span>T<span class="op">></span></code>). |
969 | | -<span class="citation" data-cites="P3074R3">[<a href="https://wg21.link/p3074r3" role="doc-biblioref">P3074R3</a>]</span> proposed either the third or |
| 972 | +<span class="citation" data-cites="P3074R3"><a href="https://wg21.link/p3074r3" role="doc-biblioref">[P3074R3]</a></span> proposed either the third or |
970 | 973 | fourth. This revision (R4) proposes specifically the third (just make it |
971 | 974 | work).</p> |
972 | 975 | <p>Let’s go over some of the solutions.</p> |
@@ -994,8 +997,9 @@ <h2 data-number="3.1" id="a-library-type-stduninitializedt"><span class="header- |
994 | 997 | <p><code class="sourceCode cpp">std<span class="op">::</span>inplace_vector<span class="op"><</span>T, N<span class="op">></span></code> |
995 | 998 | would then have a <code class="sourceCode cpp">std<span class="op">::</span>uninitialized<span class="op"><</span>T<span class="op">[</span>N<span class="op">]></span></code> |
996 | 999 | and go ahead and <code class="sourceCode cpp">std<span class="op">::</span>construct_at</code> |
997 | | -(or, with <span class="citation" data-cites="P2747R2">[<a href="https://wg21.link/p2747r2" role="doc-biblioref">P2747R2</a>]</span>, simply placement-new) into the |
998 | | -appropriate elements of that array and everything would just work.</p> |
| 1000 | +(or, with <span class="citation" data-cites="P2747R2"><a href="https://wg21.link/p2747r2" role="doc-biblioref">[P2747R2]</a></span>, simply placement-new) into |
| 1001 | +the appropriate elements of that array and everything would just |
| 1002 | +work.</p> |
999 | 1003 | <p>Because the language would recognize this type, this would also solve |
1000 | 1004 | the overlapping objects problem.</p> |
1001 | 1005 | <h2 data-number="3.2" id="a-language-annotation"><span class="header-section-number">3.2</span> A language annotation<a href="#a-language-annotation" class="self-link"></a></h2> |
@@ -1272,7 +1276,7 @@ <h2 data-number="3.5" id="existing-practice"><span class="header-section-number" |
1272 | 1276 | purpose.</p> |
1273 | 1277 | <h2 data-number="3.6" id="st.-louis-meeting-2024"><span class="header-section-number">3.6</span> St. Louis Meeting, 2024<a href="#st.-louis-meeting-2024" class="self-link"></a></h2> |
1274 | 1278 | <p>In <a href="https://github.com/cplusplus/papers/issues/1734#issuecomment-2195769496">St. Louis</a>, |
1275 | | -we discussed a previous revision of this paper (<span class="citation" data-cites="P3074R3">[<a href="https://wg21.link/p3074r3" role="doc-biblioref">P3074R3</a>]</span>), specifically the <a href="#trivial-unions">trivial union</a> and <a href="#just-make-it-work">just make it work</a> designs. There, EWG |
| 1279 | +we discussed a previous revision of this paper (<span class="citation" data-cites="P3074R3"><a href="https://wg21.link/p3074r3" role="doc-biblioref">[P3074R3]</a></span>), specifically the <a href="#trivial-unions">trivial union</a> and <a href="#just-make-it-work">just make it work</a> designs. There, EWG |
1276 | 1280 | expressed a clear preference for “just make it work”:</p> |
1277 | 1281 | <table> |
1278 | 1282 | <thead> |
@@ -1627,11 +1631,11 @@ <h2 data-number="4.2" id="language-wording"><span class="header-section-number"> |
1627 | 1631 | </blockquote> |
1628 | 1632 | </div> |
1629 | 1633 | <h2 data-number="4.3" id="library-wording"><span class="header-section-number">4.3</span> Library Wording<a href="#library-wording" class="self-link"></a></h2> |
1630 | | -<p>While this paper was in flight, <span class="citation" data-cites="P0843R14">[<a href="https://wg21.link/p0843r14" role="doc-biblioref">P0843R14</a>]</span> was moved, which had to work |
| 1634 | +<p>While this paper was in flight, <span class="citation" data-cites="P0843R14"><a href="https://wg21.link/p0843r14" role="doc-biblioref">[P0843R14]</a></span> was moved, which had to work |
1631 | 1635 | around the lack of ability to actually support non-trivial types during |
1632 | 1636 | constant evaluation. Since this paper now provides that, might as well |
1633 | 1637 | fix the library to account for the new functionality.</p> |
1634 | | -<p>Strike <span>24.3.14.1 <a href="https://wg21.link/inplace.vector.overview">[inplace.vector.overview]</a></span>/4:</p> |
| 1638 | +<p>Strike <span>23.3.14.1 <a href="https://wg21.link/inplace.vector.overview">[inplace.vector.overview]</a></span>/4:</p> |
1635 | 1639 | <div class="std"> |
1636 | 1640 | <blockquote> |
1637 | 1641 | <p><span class="marginalizedparent"><a class="marginalized" href="#pnum_23" id="pnum_23">3</a></span> |
|
0 commit comments