<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3123: duration constructor from representation shouldn't be effectively non-throwing</title>
<meta property="og:title" content="Issue 3123: duration constructor from representation shouldn't be effectively non-throwing">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3123.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<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#C++23">C++23</a> status.</em></p>
<h3 id="3123"><a href="lwg-defects.html#3123">3123</a>. <code>duration</code> constructor from representation shouldn't be effectively non-throwing</h3>
<p><b>Section:</b> 30.5 <a href="https://wg21.link/time.duration">[time.duration]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Johel Ernesto Guerrero Pe&ntilde;a <b>Opened:</b> 2018-06-22 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#time.duration">issues</a> in [time.duration].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
[time.duration]/4 states:
</p>
<blockquote><p>
Members of duration shall not throw exceptions other than those thrown by the indicated operations on their representations.
</p></blockquote>
<p>
Where representation is defined in the non-normative, brief description at [time.duration]/1:
</p>
<blockquote><p>
[&hellip;] A duration has a representation which holds a count of ticks and a tick period. [&hellip;]
</p></blockquote>
<p>
[time.duration.cons]/2 doesn't indicate the operation undergone by its representation, merely stating a postcondition in [time.duration.cons]/3:
</p>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>duration</code>.
<p/>
<i>Postconditions:</i> <code>count() == static_cast&lt;rep&gt;(r)</code>.
</p>
</blockquote>
<p>
I suggest this reformulation that follows the format of [time.duration.cons]/5.
</p>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type duration, constructing <code>rep_</code> from <code>r</code>.
</p>
</blockquote>
<p>
Now it is clear why the constructor would throw.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4750">N4750</a>.
</p>

<p>Change 30.5.2 <a href="https://wg21.link/time.duration.cons">[time.duration.cons]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class Rep2&gt;
  constexpr explicit duration(const Rep2&amp; r);
</pre>
<blockquote>
<p>
-1- <i>Remarks:</i> This constructor shall not participate in overload resolution unless [&hellip;]
<p/>
-2- <i>Effects:</i> Constructs an object of type <code>duration</code><ins>, constructing <code>rep_</code> from <code>r</code></ins>.
<p/>
-3- <i>Postconditions:</i> <code>count() == static_cast&lt;rep&gt;(r)</code>.
</p>
</blockquote>
</blockquote></blockquote>

<p><i>[2018-06-27 after reflector discussion]</i></p>

<p>Priority set to 3. Improved wording as result of that discussion.</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4750">N4750</a>.
</p>

<p>Change 30.5.2 <a href="https://wg21.link/time.duration.cons">[time.duration.cons]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class Rep2&gt;
  constexpr explicit duration(const Rep2&amp; r);
</pre>
<blockquote>
<p>
-1- <i>Remarks:</i> This constructor shall not participate in overload resolution unless [&hellip;]
<p/>
-2- <i>Effects:</i> <del>Constructs an object of type <code>duration</code></del><ins>Initializes <code>rep_</code> with <code>r</code></ins>.
<p/>
<del>-3- <i>Postconditions:</i> <code>count() == static_cast&lt;rep&gt;(r)</code>.</del>
</p>
</blockquote>
</blockquote>
</blockquote>

<p><i>[2020-05-02; Daniel resyncs wording with recent working draft]</i></p>


<p><i>[2021-09-20; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after seven votes in favour during reflector poll.
</p>

<p><i>[2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3123"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4861">N4861</a>.
</p>

<p>Change 30.5.2 <a href="https://wg21.link/time.duration.cons">[time.duration.cons]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class Rep2&gt;
  constexpr explicit duration(const Rep2&amp; r);
</pre>
<blockquote>
<p>
-1- <i>Constraints:</i> <code>is_convertible_v&lt;const Rep2&amp;, rep&gt;</code> is <code>true</code> and
</p>
<ol style="list-style-type: none">
<li><p>(1.1) &mdash; <code>treat_as_floating_point_v&lt;rep&gt;</code> is <code>true</code> or</p></li>
<li><p>(1.2) &mdash; <code>treat_as_floating_point_v&lt;Rep2&gt;</code> is <code>false</code>.</p></li>
</ol>
<p>
[<i>Example:</i> [&hellip;] <i>end example</i>]
<p/>
<ins>-?- <i>Effects:</i> Initializes <code>rep_</code> with <code>r</code>.</ins>
<p/>
<del>-2- <i>Postconditions:</i> <code>count() == static_cast&lt;rep&gt;(r)</code>.</del>
</p>
</blockquote>
</blockquote>





</body>
</html>
