<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4139: &sect;[time.zone.leap] recursive constraint in &lt;=&gt;</title>
<meta property="og:title" content="Issue 4139: &sect;[time.zone.leap] recursive constraint in &lt;=&gt;">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4139.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#New">New</a> status.</em></p>
<h3 id="4139"><a href="lwg-active.html#4139">4139</a>. &sect;[time.zone.leap] recursive constraint in <code>&lt;=&gt;</code></h3>
<p><b>Section:</b> 30.11.8 <a href="https://wg21.link/time.zone.leap">[time.zone.leap]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Corentin <b>Opened:</b> 2024-08-18 <b>Last modified:</b> 2024-08-21</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#time.zone.leap">issues</a> in [time.zone.leap].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Consider
</p>
<blockquote><pre>
decltype(std::declval&lt;std::chrono::leap_second&amp;>() &lt;=&gt; std::chrono::system_clock::now())
</pre></blockquote>
<p>
There is a <code>&lt;=&gt;</code> operator for leap second defined as
</p>
<blockquote><pre>
template&lt;class Duration&gt;
  requires three_way_comparable_with&lt;sys_seconds, sys_time&lt;Duration&gt;&gt;
  constexpr auto operator&lt;=&gt;(const leap_second&amp; x, const sys_time&lt;Duration&gt;&amp; y) noexcept;
</pre></blockquote>
<p>
In order to resolve this overload, we need to check the constraints.
<code>three_way_comparable_with</code> will end up checking that <code>sys_seconds{} &lt; sys_time&lt;Duration&gt;{}</code> 
is a valid expression. 
To do that, we run overload resolution, find a bunch of <code>operator&lt;=&gt;</code>, including the <code>leap_second</code> 
overload mentioned above.
We check its constraints... and we find ourselves doing that recursively.
<p/>
This problem currently doesn't manifest in production compilers because of a number of 
<a href="https://lists.isocpp.org/core/2023/03/14041.php">non-conforming behaviors of 
all implementations</a>, but surfaced while fixing some of these issues in clang.
<p/>
libstdc++ also does not suffer from this issue because <code>leap_seconds</code> comparisons operators are all hidden 
friends (in fact, libstdc++ define hidden friends comparison operators for most of the objects in chrono, which is 
nice!)
<p/>
Suggested resolution:
<p/>
Specify that <code>leap_seconds</code> operators are hidden friends. This would avoid the recursion, and would be easier 
on compilers.
</p>

<p><i>[2024-08-21; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
Support for changing all relational ops for calendar types to hidden friends,
but only doing it for <code class='backtick'>leap_second</code> would be in scope for this issue.
</p>



<p id="res-4139"><b>Proposed resolution:</b></p>





</body>
</html>
