<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1177: Improve "diagnostic required" wording</title>
<meta property="og:title" content="Issue 1177: Improve &quot;diagnostic required&quot; wording">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1177.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++11">C++11</a> status.</em></p>
<h3 id="1177"><a href="lwg-defects.html#1177">1177</a>. Improve "diagnostic required" wording</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++11">C++11</a>
 <b>Submitter:</b> Howard Hinnant <b>Opened:</b> 2009-07-18 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</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++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
"diagnostic required" has been used (by me) for code words meaning "use
<code>enable_if</code> to constrain templated functions.  This needs to be
improved by referring to the function signature as not participating in
the overload set, and moving this wording to a <i>Remarks</i> paragraph.
</p>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Moved to Ready.
</p></blockquote>

<p><i>[
2009-11-19 Pete opens:
]</i></p>


<blockquote>
<p>
Oh, and speaking of 1177, most of the changes result in rather convoluted prose.
Instead of saying
</p>

<blockquote><p>
A shall be B, else C
</p></blockquote>

<p>
it should be
</p>

<blockquote><p>
C if A is not B
</p></blockquote>

<p>
That is:
</p>

<blockquote><p>
<code>Rep2</code> shall be implicitly convertible to <code>CR(Rep1, Rep2)</code>, else
this signature shall not participate in overload resolution.
</p></blockquote>

<p>
should be
</p>

<blockquote><p>
This signature shall not participate in overload resolution if <code>Rep2</code> is
not implicitly convertible to <code>CR(Rep1, Rep2)</code>.
</p></blockquote>

<p>
That is clearer, and eliminates the false requirement that <code>Rep2</code> "shall
be" convertible.
</p>

</blockquote>

<p><i>[
2009-11-19 Howard adds:
]</i></p>


<blockquote><p>
I've updated the wording to match Pete's suggestion and included bullet 16
from <a href="lwg-defects.html#1195" title="&quot;Diagnostic required&quot; wording is insufficient to  prevent UB (Status: C++11)">1195</a><sup><a href="https://cplusplus.github.io/LWG/issue1195" title="Latest snapshot">(i)</a></sup>.
</p></blockquote>

<p><i>[
2009-11-19 Jens adds:
]</i></p>


<blockquote>
<p>
Further wording suggestion using "unless":
</p>

<blockquote><p>
This signature shall not participate in overload resolution unless <code>Rep2</code>
is implicitly convertible to <code>CR(Rep1, Rep2)</code>.
</p></blockquote>
</blockquote>

<p><i>[
2009-11-20 Howard adds:
]</i></p>


<blockquote><p>
I've updated the wording to match Jens' suggestion.
</p></blockquote>

<p><i>[
2009-11-22 Moved to Tentatively Ready after 5 positive votes on c++std-lib.
]</i></p>




<p id="res-1177"><b>Proposed resolution:</b></p>
<p><i>[
This proposed resolution addresses <a href="lwg-defects.html#947" title="duration arithmetic: contradictory requirements (Status: Resolved)">947</a><sup><a href="https://cplusplus.github.io/LWG/issue947" title="Latest snapshot">(i)</a></sup> and <a href="lwg-defects.html#974" title="duration&lt;double&gt; should not implicitly convert to duration&lt;int&gt; (Status: C++11)">974</a><sup><a href="https://cplusplus.github.io/LWG/issue974" title="Latest snapshot">(i)</a></sup>. 
]</i></p>


<ol>
<li>
<p>
Change 30.5.2 <a href="https://wg21.link/time.duration.cons">[time.duration.cons]</a> (and reorder the <i>Remarks</i>
paragraphs per 16.3.2.4 <a href="https://wg21.link/structure.specifications">[structure.specifications]</a>):
</p>

<blockquote>
<pre>
template &lt;class Rep2&gt; 
  explicit duration(const Rep2&amp; r);
</pre>
<blockquote>
<p>
<i><del>Requires:</del> <ins>Remarks:</ins></i> <ins>This constructor shall not
participate in overload resolution unless</ins> <code>Rep2</code> <del>shall be</del>
<ins>is</ins> implicitly convertible to <code>rep</code> and
</p>
<ul>
<li>
<code>treat_as_floating_point&lt;rep&gt;::value</code> <del>shall be</del>
<ins>is</ins> <code>true</code><ins>,</ins> or
</li>
<li>
<code>treat_as_floating_point&lt;Rep2&gt;::value</code> <del>shall be</del>
<ins>is</ins> <code>false</code>.
</li>
</ul>
<p>
<del>Diagnostic required</del> [<i>Example:</i>
</p>
<blockquote><pre>
duration&lt;int, milli&gt; d(3); // OK 
duration&lt;int, milli&gt; d(3.5); // error 
</pre></blockquote>

<p>
&mdash; <i>end example</i>]
</p>

<p>
<i>Effects:</i> Constructs an object of type <code>duration</code>.
</p>

<p>
<i>Postcondition:</i> <code>count() == static_cast&lt;rep&gt;(r)</code>.
</p>

</blockquote>

<pre>
template &lt;class Rep2, class Period2&gt;
  duration(const duration&lt;Rep2, Period2&gt;&amp; d);
</pre>
<blockquote>
<p>
<i><del>Requires:</del> <ins>Remarks:</ins></i> <ins>This constructor shall not
participate in overload resolution unless</ins>
<code>treat_as_floating_point&lt;rep&gt;::value</code> <del>shall be</del>
<ins>is</ins> <code>true</code> or <code>ratio_divide&lt;Period2,
period&gt;::type::den</code> <del>shall be</del> <ins>is</ins> 1. <del>Diagnostic
required.</del> [<i>Note:</i> This requirement prevents implicit truncation
error when converting between integral-based duration types. Such a construction
could easily lead to confusion about the value of the duration. &mdash; <i>end
note</i>] [<i>Example:</i>
</p>

<blockquote><pre>
duration&lt;int, milli&gt; ms(3); 
duration&lt;int, micro&gt; us = ms; // OK 
duration&lt;int, milli&gt; ms2 = us; // error 
</pre></blockquote>

<p>
&mdash; <i>end example</i>]
</p>

<p>
<i>Effects:</i> Constructs an object of type <code>duration</code>, constructing
<code>rep_</code> from
<code>duration_cast&lt;duration&gt;(d).count()</code>.
</p>

</blockquote>


</blockquote>
</li>

<li>
<p>
Change the following paragraphs in 30.5.6 <a href="https://wg21.link/time.duration.nonmember">[time.duration.nonmember]</a>:
</p>

<blockquote>
<pre>
template &lt;class Rep1, class Period, class Rep2&gt; 
  duration&lt;typename common_type&lt;Rep1, Rep2&gt;::type, Period&gt; 
  operator*(const duration&lt;Rep1, Period&gt;&amp; d, const Rep2&amp; s);
</pre>
<blockquote><p>
<i><del>Requires</del> <ins>Remarks</ins>:</i> <ins>This operator shall not
participate in overload resolution unless</ins> <code>Rep2</code> <del>shall
be</del> <ins>is</ins> implicitly convertible to <code>CR(Rep1, Rep2)</code>.
<del>Diagnostic required.</del>
</p></blockquote>

<pre>
template &lt;class Rep1, class Period, class Rep2&gt; 
  duration&lt;typename common_type&lt;Rep1, Rep2&gt;::type, Period&gt; 
  operator*(const Rep1&amp; s, const duration&lt;Rep2, Period&gt;&amp; d);
</pre>
<blockquote><p>
<i><del>Requires</del> <ins>Remarks</ins>:</i> <ins>This operator shall not
participate in overload resolution unless</ins> <code>Rep1</code> <del>shall
be</del> <ins>is</ins> implicitly convertible to <code>CR(Rep1, Rep2)</code>.
<del>Diagnostic required.</del>
</p></blockquote>

<pre>
template &lt;class Rep1, class Period, class Rep2&gt; 
  duration&lt;typename common_type&lt;Rep1, Rep2&gt;::type, Period&gt; 
  operator/(const duration&lt;Rep1, Period&gt;&amp; d, const Rep2&amp; s);
</pre>
<blockquote><p>
<i><del>Requires</del> <ins>Remarks</ins>:</i> <ins>This operator shall not
participate in overload resolution unless</ins> <code>Rep2</code> <del>shall
be</del> <ins>is</ins> implicitly convertible to <code>CR(Rep1, Rep2)</code> and
<code>Rep2</code> <del>shall not be</del> <ins>is not</ins> an instantiation of
<code>duration</code>. <del>Diagnostic required.</del>
</p></blockquote>

<pre>
template &lt;class Rep1, class Period, class Rep2&gt; 
  duration&lt;typename common_type&lt;Rep1, Rep2&gt;::type, Period&gt; 
  operator%(const duration&lt;Rep1, Period&gt;&amp; d, const Rep2&amp; s);
</pre>
<blockquote><p>
<i><del>Requires</del> <ins>Remarks</ins>:</i> <ins>This operator shall not
participate in overload resolution unless</ins> <code>Rep2</code> <del>shall
be</del> <ins>is</ins> implicitly convertible to <code>CR(Rep1, Rep2)</code> and
<code>Rep2</code> <del>shall not be</del> <ins>is not</ins> an instantiation of
<code>duration</code>. <del>Diagnostic required.</del>
</p></blockquote>

</blockquote>
</li>

<li>
<p>
Change the following paragraphs in 30.5.8 <a href="https://wg21.link/time.duration.cast">[time.duration.cast]</a>:
</p>

<blockquote><pre>
template &lt;class ToDuration, class Rep, class Period&gt; 
  ToDuration duration_cast(const duration&lt;Rep, Period&gt;&amp; d);
</pre>

<blockquote><p>
<i><del>Requires</del> <ins>Remarks</ins>:</i> <ins>This function shall not
participate in overload resolution unless</ins> <code>ToDuration</code> <del>shall
be</del> <ins>is</ins> an instantiation of <code>duration</code>. <del>Diagnostic
required.</del>
</p></blockquote>
</blockquote>
</li>

<li>
<p>
Change 30.6.2 <a href="https://wg21.link/time.point.cons">[time.point.cons]</a>/3 as indicated:
</p>

<blockquote>
<p>
<del><i>Requires:</i> <code>Duration2</code> shall be implicitly convertible to <code>duration</code>.
Diagnostic required.</del>
</p>

<p>
<ins><i>Remarks:</i> This constructor shall not participate in overload
resolution unless <code>Duration2</code> is implicitly convertible to
<code>duration</code>.</ins>
</p>
</blockquote>

</li>

<li>
<p>
Change the following paragraphs in 30.6.8 <a href="https://wg21.link/time.point.cast">[time.point.cast]</a>:
</p>

<blockquote><pre>
template &lt;class ToDuration, class Clock, class Duration&gt; 
  time_point&lt;Clock, ToDuration&gt; time_point_cast(const time_point&lt;Clock, Duration&gt;&amp; t);
</pre>

<blockquote><p>
<i><del>Requires</del> <ins>Remarks</ins>:</i> <ins>This function shall not
participate in overload resolution unless</ins> <code>ToDuration</code> <del>shall
be</del> <ins>is</ins> an instantiation of <code>duration</code>. <del>Diagnostic
required.</del>
</p></blockquote>
</blockquote>
</li>
</ol>






</body>
</html>
