|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<title>Issue 4282: Imprecise Throws: clause in std::relocate</title> |
| 6 | +<meta property="og:title" content="Issue 4282: Imprecise Throws: clause in std::relocate"> |
| 7 | +<meta property="og:description" content="C++ library issue. Status: New"> |
| 8 | +<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4282.html"> |
| 9 | +<meta property="og:type" content="website"> |
| 10 | +<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png"> |
| 11 | +<meta property="og:image:alt" content="C++ logo"> |
| 12 | +<style> |
| 13 | + p {text-align:justify} |
| 14 | + li {text-align:justify} |
| 15 | + pre code.backtick::before { content: "`" } |
| 16 | + pre code.backtick::after { content: "`" } |
| 17 | + blockquote.note |
| 18 | + { |
| 19 | + background-color:#E0E0E0; |
| 20 | + padding-left: 15px; |
| 21 | + padding-right: 15px; |
| 22 | + padding-top: 1px; |
| 23 | + padding-bottom: 1px; |
| 24 | + } |
| 25 | + ins {background-color:#A0FFA0} |
| 26 | + del {background-color:#FFA0A0} |
| 27 | + table.issues-index { border: 1px solid; border-collapse: collapse; } |
| 28 | + table.issues-index th { text-align: center; padding: 4px; border: 1px solid; } |
| 29 | + table.issues-index td { padding: 4px; border: 1px solid; } |
| 30 | + table.issues-index td:nth-child(1) { text-align: right; } |
| 31 | + table.issues-index td:nth-child(2) { text-align: left; } |
| 32 | + table.issues-index td:nth-child(3) { text-align: left; } |
| 33 | + table.issues-index td:nth-child(4) { text-align: left; } |
| 34 | + table.issues-index td:nth-child(5) { text-align: center; } |
| 35 | + table.issues-index td:nth-child(6) { text-align: center; } |
| 36 | + table.issues-index td:nth-child(7) { text-align: left; } |
| 37 | + table.issues-index td:nth-child(5) span.no-pr { color: red; } |
| 38 | + @media (prefers-color-scheme: dark) { |
| 39 | + html { |
| 40 | + color: #ddd; |
| 41 | + background-color: black; |
| 42 | + } |
| 43 | + ins { |
| 44 | + background-color: #225522 |
| 45 | + } |
| 46 | + del { |
| 47 | + background-color: #662222 |
| 48 | + } |
| 49 | + a { |
| 50 | + color: #6af |
| 51 | + } |
| 52 | + a:visited { |
| 53 | + color: #6af |
| 54 | + } |
| 55 | + blockquote.note |
| 56 | + { |
| 57 | + background-color: rgba(255, 255, 255, .10) |
| 58 | + } |
| 59 | + } |
| 60 | +</style> |
| 61 | +</head> |
| 62 | +<body> |
| 63 | +<hr> |
| 64 | +<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p> |
| 65 | +<h3 id="4282"><a href="lwg-active.html#4282">4282</a>. Imprecise <i>Throws</i>: clause in <code class='backtick'>std::relocate</code></h3> |
| 66 | +<p><b>Section:</b> 20.2.6 <a href="https://wg21.link/obj.lifetime">[obj.lifetime]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a> |
| 67 | + <b>Submitter:</b> Giuseppe D'Angelo <b>Opened:</b> 2025-06-23 <b>Last modified:</b> 2025-06-28</p> |
| 68 | +<p><b>Priority: </b>Not Prioritized |
| 69 | +</p> |
| 70 | +<p><b>View other</b> <a href="lwg-index-open.html#obj.lifetime">active issues</a> in [obj.lifetime].</p> |
| 71 | +<p><b>View all other</b> <a href="lwg-index.html#obj.lifetime">issues</a> in [obj.lifetime].</p> |
| 72 | +<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p> |
| 73 | +<p><b>Discussion:</b></p> |
| 74 | +<p> |
| 75 | +The current specification of <code class='backtick'>std::relocate</code> in 20.2.6 <a href="https://wg21.link/obj.lifetime">[obj.lifetime]</a> says |
| 76 | +</p> |
| 77 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 78 | +<p> |
| 79 | +<i>Throws</i>: Nothing. |
| 80 | +</p> |
| 81 | +</blockquote> |
| 82 | +<p> |
| 83 | +This is imprecise. A trivially relocatable type may feature a throwing |
| 84 | +move constructor (or a throwing destructor); for instance, a linked-list |
| 85 | +implementation with an externally allocated sentinel node may have a |
| 86 | +throwing move constructor, but still be trivially relocatable. Such a |
| 87 | +type is nothrow relocatable (as per <code class='backtick'>is_nothrow_relocatable_v</code>, cf. |
| 88 | +21.3.5.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a>) and therefore one can call <code class='backtick'>std::relocate</code> |
| 89 | +on objects of that type. |
| 90 | +<p/> |
| 91 | +During constant evaluation, a call to <code class='backtick'>std::relocate</code> is specified to |
| 92 | +relocate objects via move construction and destruction. |
| 93 | +(<code class='backtick'>std::trivially_relocate</code> is unavailable during constant evaluation.) |
| 94 | +<p/> |
| 95 | +Since <a href="https://wg21.link/P3068" title=" Allowing exception throwing in constant-evaluation">P3068</a> we are allowed to throw during constant evaluation, |
| 96 | +and therefore it's unclear whether <code class='backtick'>std::relocate</code> should propagate such an |
| 97 | +exception to the caller or should instead make the evaluation not a |
| 98 | +constant expression (and therefore make the program ill-formed, since by |
| 99 | +construction we end up in this possibility during constant evaluation). |
| 100 | +<p/> |
| 101 | +Given the rationale brought forward for <code class='backtick'>std::relocate</code> in <a href="https://wg21.link/P2786" title=" Trivial Relocatability For C++26">P2786</a> |
| 102 | +is to be always a nofail operation, I'm proposing a resolution that goes in |
| 103 | +that direction. |
| 104 | +</p> |
| 105 | + |
| 106 | + |
| 107 | +<p id="res-4282"><b>Proposed resolution:</b></p> |
| 108 | +<p> |
| 109 | +This wording is relative to <a href="https://wg21.link/N5008">N5008</a>. |
| 110 | +</p> |
| 111 | + |
| 112 | +<ol> |
| 113 | +<li><p>Modify 20.2.6 <a href="https://wg21.link/obj.lifetime">[obj.lifetime]</a> as indicated:</p> |
| 114 | + |
| 115 | +<blockquote> |
| 116 | +<pre> |
| 117 | +template<class T> |
| 118 | + constexpr T* relocate(T* first, T* last, T* result); |
| 119 | +</pre> |
| 120 | +<blockquote> |
| 121 | +<p> |
| 122 | +-16 <i>Mandates</i>: […] |
| 123 | +<p/> |
| 124 | +-17- <i>Preconditions</i>: […] |
| 125 | +<p/> |
| 126 | +-18- <i>Effects</i>: […] |
| 127 | +<p/> |
| 128 | +-19- <i>Returns</i>: <code class='backtick'>result + (last - first)</code>. |
| 129 | +<p/> |
| 130 | +-20- <i>Throws:</i>: Nothing. |
| 131 | +<p/> |
| 132 | +<ins>-?- <i>Remarks</i>: If <code class='backtick'>relocate</code> is called during constant evaluation, and an |
| 133 | +exception is thrown by a constructor or destructor of <code class='backtick'>T</code>, the call to <code class='backtick'>relocate</code> |
| 134 | +is not a core constant expression (7.7 <a href="https://wg21.link/expr.const">[expr.const]</a>).</ins> |
| 135 | +<p/> |
| 136 | +[<i>Note 3</i>: Overlapping ranges are supported. — <i>end note</i>] |
| 137 | +</p> |
| 138 | +</blockquote> |
| 139 | +</blockquote> |
| 140 | +</li> |
| 141 | + |
| 142 | +</ol> |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | +</body> |
| 149 | +</html> |
0 commit comments