Skip to content

Commit

Permalink
New issue from Corentin: "A less hacky and more useful way to compare…
Browse files Browse the repository at this point in the history
… comparison category types"
  • Loading branch information
Dani-Hub committed Feb 4, 2024
1 parent ce49cad commit fa3bbab
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions xml/issue4051.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">

<issue num="4051" status="New">
<title>A less hacky and more useful way to compare comparison category types</title>
<section><sref ref="[cmp.categories]"/></section>
<submitter>Corentin Jabot</submitter>
<date>31 Jan 2024</date>
<priority>99</priority>

<discussion>
<p>
Comparison categories can only be compared to the literal <tt>0</tt>.
It does not make sense for them to be comparable to anything else, so conceptually, the design of
<paper num="P0515"/> makes sense, however in practice it's a pain point from users and implementations
alike, as the desired semantics is barely implementable.
</p>
<ul>
<li><p>One implementation strategy is to use <tt>nullptr_t</tt>. This produces warnings in implementations
because using a <tt>0</tt> pointer constant is not recommended, and filtering out these warnings would be unreliable.</p></li>
<li><p>Another implementation strategy is to require a <tt>consteval</tt> expression but</p>
<ul>
<li><p>This permits <tt>1-1</tt>, which ought to be totally fine and yet it exposes users to UB</p></li>
<li><p>It is not SFINAE friendly (and attempts at SFINAE are presumably UB).</p></li>
</ul>
</li>
</ul>
<p>
And there are use cases where SFINAE friendliness is important, notably testing frameworks.
<p/>
The status quo has engendered multiple issues being reported to at least 3 vendors
<p/>
Suggestion:
</p>
<ul>
<li><p>Allow any <tt>0</tt> constant expression</p></li>
<li><p>Require compile magic to SFINAE on non zero values</p></li>
<li><p>Remove the gratuitous UB</p></li>
</ul>
<p>
The proposed wording requires compiler magic and has been
<a href="https://godbolt.org/z/1xr9Wx38T">implemented in clang</a>.
(Other possible way to implement that would for example be a magic type attribute, or a magic type)
<p/>
Related vendor issues:
<p/>
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96278">GCC Bugzilla issue 96278</a>
<p/>
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903">GCC Bugzilla issue 100903</a>
<p/>
<a href="https://github.com/llvm/llvm-project/issues/43670">LLVM issue 43670</a>
<p/>
<a href="https://github.com/llvm/llvm-project/pull/79465">LLVM pulls request 79465</a>
<p/>
<a href="https://github.com/microsoft/STL/issues/4359">Microsoft STL issue 4359</a>
<p/>
<a href="https://github.com/microsoft/STL/pull/3581">Microsoft STL pull request 3581</a>
<p/>
<a href="https://developercommunity.visualstudio.com/t/Regression:-False-positive-C7595:-std::/10509214">Visual Studio issue 10509214</a>
<p/>
<a href="https://github.com/snitch-org/snitch/issues/140">snitch issue 140</a>
</p>
</discussion>

<resolution>
<p>
This wording is relative to <paper num="N4971"/>.
</p>

<ol>
<li><p>Modify <sref ref="[cmp.categories.pre]"/> as indicated:</p>

<blockquote>
<p>
-3- The relational and equality operators for the comparison category types are specified with an anonymous
parameter of unspecified type. This type shall be selected by the implementation such that these parameters
can <ins>only</ins> accept <ins>an integral constant expression evaluating to</ins><del>literal</del> <tt>0</tt>
as a corresponding argument.
<p/>
<del>[<i>Example 1</i>: <tt>nullptr_t</tt> meets this requirement. &mdash; <i>end example</i>]</del>
<p/>
<del>In this context, the behavior of a program that supplies an argument other than a literal <tt>0</tt> is undefined.</del>
</p>
</blockquote>
</li>
</ol>
</resolution>

</issue>

0 comments on commit fa3bbab

Please sign in to comment.