public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/104606] [11/12/13/14 Regression] comparison operator resolution with std::optional and -std=c++20
Date: Wed, 27 Mar 2024 21:41:16 +0000	[thread overview]
Message-ID: <bug-104606-4-VRGwNDKD9U@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104606-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104606

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
std::optional's spaceship operator currently looks like this:

  template<typename _Tp, typename _Up>
    requires (!__is_optional_v<_Up>)
      && three_way_comparable_with<_Tp, _Up>
    constexpr compare_three_way_result_t<_Tp, _Up>
    operator<=>(const optional<_Tp>& __x, const _Up& __v)

As Jakub noted, if we revert the LWG 3566 change it works:

  template<typename _Tp, three_way_comparable_with<_Tp> _Up>
    constexpr compare_three_way_result_t<_Tp, _Up>
    operator<=>(const optional<_Tp>& __x, const _Up& __v)

We can rewrite that to this, which should be exactly equivalent, and it still
works:

  template<typename _Tp, typename _Up>
    requires three_way_comparable_with<_Up, _Tp>
    constexpr compare_three_way_result_t<_Tp, _Up>
    operator<=>(const optional<_Tp>& __x, const _Up& __v)

and then we can add the !is-optional<U> constraint back in:

  template<typename _Tp, typename _Up>
    requires
    (!__is_optional_v<_Up>) &&
      three_way_comparable_with<_Up, _Tp>
    constexpr compare_three_way_result_t<_Tp, _Up>
    operator<=>(const optional<_Tp>& __x, const _Up& __v)

And it still works! The only difference is:
  three_way_comparable_with<_Up, _Tp>
vs
  three_way_comparable_with<_Tp, _Up>

This should not matter, but it does.

So there definitely seems to be a front end bug here, but at least there's an
easy fix for the library.

  parent reply	other threads:[~2024-03-27 21:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-19 16:03 [Bug libstdc++/104606] New: Regression in comparison operator resolution with std::optional julien.philippon at epitech dot eu
2022-02-19 16:07 ` [Bug libstdc++/104606] " julien.philippon at epitech dot eu
2022-02-19 22:17 ` [Bug c++/104606] [11/12 Regression] comparison operator resolution with std::optional and -std=c++20 pinskia at gcc dot gnu.org
2022-02-19 22:38 ` jakub at gcc dot gnu.org
2022-02-19 22:46 ` jakub at gcc dot gnu.org
2022-02-19 22:59 ` [Bug libstdc++/104606] [10/11/12 " pinskia at gcc dot gnu.org
2022-02-20  7:38 ` jakub at gcc dot gnu.org
2022-02-20  7:45 ` jakub at gcc dot gnu.org
2022-02-21  9:47 ` rguenth at gcc dot gnu.org
2022-02-21 21:01 ` redi at gcc dot gnu.org
2022-06-28 10:48 ` [Bug libstdc++/104606] [10/11/12/13 " jakub at gcc dot gnu.org
2023-07-07 10:42 ` [Bug libstdc++/104606] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-03-27 20:58 ` redi at gcc dot gnu.org
2024-03-27 21:41 ` redi at gcc dot gnu.org [this message]
2024-03-27 23:11 ` redi at gcc dot gnu.org
2024-04-03 10:53 ` cvs-commit at gcc dot gnu.org
2024-05-02 14:16 ` [Bug libstdc++/104606] [11/12/13 " cvs-commit at gcc dot gnu.org
2024-05-02 14:16 ` [Bug libstdc++/104606] [11/12 " redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104606-4-VRGwNDKD9U@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).