<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3294: zoned_time deduction guides misinterprets string/char*</title>
<meta property="og:title" content="Issue 3294: zoned_time deduction guides misinterprets string/char*">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3294.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++20">C++20</a> status.</em></p>
<h3 id="3294"><a href="lwg-defects.html#3294">3294</a>. <code>zoned_time</code> deduction guides misinterprets <code>string</code>/<code>char*</code></h3>
<p><b>Section:</b> 30.11.7.1 <a href="https://wg21.link/time.zone.zonedtime.overview">[time.zone.zonedtime.overview]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Tomasz Kami&nacute;ski <b>Opened:</b> 2019-09-14 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#time.zone.zonedtime.overview">issues</a> in [time.zone.zonedtime.overview].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The current deduction guide for <code>zoned_time</code> for the following declarations
</p>
<blockquote>
<pre>
zoned_time zpc("America/New_York", std::chrono::system_clock::now());
zoned_time zps(std::string("America/New_York"), std::chrono::system_clock::now());
</pre>
</blockquote>
<p>
will attempt to produce a <code>zoned_time</code> instance with <code>const char*</code> 
(for <code>zpc</code>) and with <code>std::string</code> (for <code>zps</code>), respectively, 
as the deduced type for the <code>TimeZonePtr</code> template parameter. This is caused by 
the fact that the unconstrained <code>TimeZonePtr</code> deduction guide template will 
produce better candidates and will be selected by overload resolution.
<p/>
The proposed resolution merges the deduction of the 
<code>std::string_view</code>/<code>TimeZonePtr</code> deduction guides
into one guide, that deduces <code>const time_zone*</code> for any type
convertible to <code>string_view</code>. This is necessary to override
the deduction from <code>TimeZonePtr</code> constructor candidates.
<p/>
In addition, we disable the deduction from <code>string_view</code>
constructors, that would produce better candidates than the deduction guides
and create <code>zoned_time</code> instances with durations coarser than
<code>seconds</code> (causing similar issue as LWG <a href="lwg-defects.html#3232" title="Inconsistency in zoned_time deduction guides (Status: C++20)">3232</a><sup><a href="https://cplusplus.github.io/LWG/issue3232" title="Latest snapshot">(i)</a></sup>):
</p>
<blockquote>
<pre>
std::chrono::local_time&lt;hours&gt; lh(10h);
std::chrono::zoned_time zt1("Europe/Helsinki", lh);
std::chrono::zoned_time zt2(std::string("Europe/Helsinki"), lh);
std::chrono::zoned_time zt3(std::string_view("Europe/Helsinki"), lh);
</pre>
</blockquote>
<p>
Without disabling the deduction from the <code>string_view</code>
constructor, the type of the <code>zt3</code> variable would be deduced to 
<code>zoned_time&lt;hours&gt;</code>, with the proposed change the types
of the variables <code>zt1</code>, <code>zt2</code>, and <code>zt3</code> 
are consistently deduced as <code>zoned_time&lt;seconds&gt;</code>.
<p/>
Finally, the wording eliminates the unnecessary <code>zoned_time&lt;Duration&gt;</code> 
guide (covered by <code>zoned_time&lt;Duration, TimeZonePtr2&gt;</code>).
<p/>
The change was implemented in the example implementation. The dedicated
test can be found 
<a href="https://github.com/HowardHinnant/date/blob/master/test/tz_test/zoned_time_deduction.pass.cpp">here</a>.
</p>

<p><i>[2019-10-31 Issue Prioritization]</i></p>

<p>Status to Tentatively Ready and priority to 0 after five positive votes on the reflector.</p>


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

<ol>
<li><p>Modify 30.11.7.1 <a href="https://wg21.link/time.zone.zonedtime.overview">[time.zone.zonedtime.overview]</a>, class template <code>zoned_time</code> 
synopsis, as indicated:</p>

<blockquote>
<blockquote>
<pre>
namespace std::chrono {
  [&hellip;]
  zoned_time() -&gt; zoned_time&lt;seconds&gt;;
  
  template&lt;class Duration&gt;
    zoned_time(sys_time&lt;Duration&gt;)
      -&gt; zoned_time&lt;common_type_t&lt;Duration, seconds&gt;&gt;;
      
  <ins>template&lt;class TimeZonePtrOrName&gt;
    using <i>time-zone-representation</i> =
      conditional_t&lt;is_convertible_v&lt;TimeZonePtrOrName, string_view&gt;, 
        const time_zone*,
        remove_cv_ref&lt;TimeZonePtrOrName&gt;&gt;; <i>// exposition only</i>

  template&lt;class TimeZonePtrOrName&gt;
    zoned_time(TimeZonePtrOrName&amp;&amp;)
      -&gt; zoned_time&lt;seconds, <i>time-zone-representation</i>&lt;TimeZonePtr&gt;&gt;;</ins>
  
  template&lt;class TimeZonePtr<ins>OrName</ins>, class Duration&gt;
    zoned_time(TimeZonePtr<ins>OrName&amp;&amp;</ins>, sys_time&lt;Duration&gt;)
      -&gt; zoned_time&lt;common_type_t&lt;Duration, seconds&gt;, 
        <ins><i>time-zone-representation</i>&lt;</ins>TimeZonePtr<ins>OrName&gt;</ins>&gt;;
  
  template&lt;class TimeZonePtr<ins>OrName</ins>, class Duration&gt;
    zoned_time(TimeZonePtr<ins>OrName&amp;&amp;</ins>, local_time&lt;Duration&gt;, choose = choose::earliest)
      -&gt; zoned_time&lt;common_type_t&lt;Duration, seconds&gt;, 
        <ins><i>time-zone-representation</i>&lt;</ins>TimeZonePtr<ins>OrName&gt;</ins>&gt;;
  
  <del>template&lt;class TimeZonePtr, class Duration&gt;
    zoned_time(TimeZonePtr, zoned_time&lt;Duration&gt;, choose = choose::earliest)
      -&gt;> zoned_time&lt;common_type_t&lt;Duration, seconds&gt;, TimeZonePtr&gt;;
  
  zoned_time(string_view) -&gt; zoned_time&lt;seconds&gt;;

  template&lt;class Duration&gt;
    zoned_time(string_view, sys_time&lt;Duration&gt;)
      -&gt; zoned_time&lt;common_type_t&lt;Duration, seconds&gt;&gt;;
  
  template&lt;class Duration&gt;
    zoned_time(string_view, local_time&lt;Duration&gt;, choose = choose::earliest)
      -&gt; zoned_time&lt;common_type_t&lt;Duration, seconds&gt;&gt;;</del>
  
  template&lt;class Duration, class TimeZonePtr<ins>OrName</ins>, class TimeZonePtr2&gt;
    zoned_time(TimeZonePtr<ins>OrName&amp;&amp;</ins>, zoned_time&lt;Duration, TimeZonePtr2&gt;, choose = choose::earliest)
     -&gt; zoned_time&lt;Duration, <ins><i>time-zone-representation</i>&lt;</ins>TimeZonePtr<ins>OrName&gt;</ins>&gt;;
}
</pre>
</blockquote>
<p>
-1- <code>zoned_time</code> represents a logical pairing of a <code>time_zone</code> and a <code>time_point</code> 
with precision <code>Duration</code>. <code>zoned_time&lt;Duration&gt;</code> maintains the invariant that it 
always refers to a valid time zone and represents a point in time that exists and is not ambiguous in 
that time zone.
<p/>
-2- If <code>Duration</code> is not a specialization of <code>chrono::duration</code>, the program is ill-formed.
<p/>
<ins>-?- Every constructor of <code>zoned_time</code> that accepts a <code>string_view</code> as first parameter 
does not participate in class template argument deduction (12.2.2.9 <a href="https://wg21.link/over.match.class.deduct">[over.match.class.deduct]</a>).</ins>
</p>
</blockquote>
</li>
</ol>





</body>
</html>
