<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal>Thank you!<o:p></o:p></p><p class=MsoNormal>I will investigate your lead and report the bug to libstdc++. I<span style='font-family:"Times New Roman",serif'>’</span>ve been hitting quite a few bugs in synthesized <=> operators lately..<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks,<o:p></o:p></p><p class=MsoNormal>Nuno<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b>From:</b> Arthur O'Dwyer <arthur.j.odwyer@gmail.com> <br><b>Sent:</b> 26 January 2021 16:14<br><b>To:</b> Nuno Lopes <nunoplopes@sapo.pt><br><b>Cc:</b> Clang Dev <cfe-dev@lists.llvm.org><br><b>Subject:</b> Re: [cfe-dev] Spaceship operator oddity with optional<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Tue, Jan 26, 2021 at 8:58 AM Nuno Lopes via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p></div><div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><p class=MsoNormal><br>I just bumped into this mysterious behavior with the spaceship operator over<br>optional:<br><br>struct expr {<br>  std::strong_ordering operator<=>(const expr &rhs) const;<br>  //bool operator==(const expr &rhs) const;<br>};<br><br>int f() {<br>  return std::is_eq(std::optional<expr>() <=> std::optional<expr>());<br>  //return std::optional<expr>() == std::optional<expr>();<br>}<br><br>Function f() returns 0 both on gcc & clang trunk<br>(<a href="https://gcc.godbolt.org/z/fv85eP" target="_blank">https://gcc.godbolt.org/z/fv85eP</a>).<br>However, if you uncomment the operator==() line, the function starts<br>returning 1.<br><br>The documentation of<br><a href="https://en.cppreference.com/w/cpp/utility/optional/operator_cmp" target="_blank">https://en.cppreference.com/w/cpp/utility/optional/operator_cmp</a> just says:<br>    7) If bool(lhs) && bool(rhs) is true returns *x <=> *y<br>      Otherwise, returns bool(lhs) <=> bool(rhs)<br><br>So no word about operator=='s existence.<br>Is this a bug in both clang & gcc or just some unobvious 3-way comparison<br>rule I'm not aware?<o:p></o:p></p></blockquote><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I haven't dug deep, but based on your description it's an issue with <b>GNU libstdc++</b>, not an issue with either of the compilers themselves.<o:p></o:p></p></div><div><p class=MsoNormal>Neither libc++ nor Microsoft STL support C++20 optional::operator<=> yet; libstdc++ is the only library vendor who's tried to implement it, and if their implementation doesn't match your expectations, then my guess is that it's a bug in their implementation. (Or, perhaps, a bug in your expectations — but I give it more than 50/50 it's an implementation bug in libstdc++. The details of operator-spaceship have changed <b><i>many</i></b> times in the past 3 years and maybe GNU libstdc++ is implementing some older version.)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><a href="https://gcc.godbolt.org/z/ofxPss">https://gcc.godbolt.org/z/ofxPss</a><o:p></o:p></p></div><div><p class=MsoNormal>My guess is that libstdc++ std::optional hasn't caught up to the compiler changes from<o:p></o:p></p></div><div><p class=MsoNormal><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1185r2.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1185r2.html</a><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>HTH,<o:p></o:p></p></div><div><p class=MsoNormal>Arthur<o:p></o:p></p></div></div></div></div></body></html>