public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ppalka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/102396] [11/12 Regression] ICE when using concepts, in get,  at cp/constraint.cc:2637 since r11-6245-g79f57d5cb070bb02
Date: Sat, 11 Dec 2021 16:13:09 +0000	[thread overview]
Message-ID: <bug-102396-4-LAZBva9DD0@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102396-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Giuseppe D'Angelo from comment #3)
> Hello Patrick,
> 
> Thank you for the insights. I'm left wondering however if the CWG resolution
> would possibly ever allow the operator== to be defined as a hidden friend;
> the workaround you mentioned may lead to redefinition errors (as now it
> doesn't depend on S any more)?

Ah yeah, I ran into a similar issue when implementing the pipe operator for
range adaptor closures in libstdc++... IIRC, I worked around this by
introducing a non-template base class and defining the hidden template friend
in the base class instead.  So something like:

#include <type_traits>
#include <concepts>


template <typename T> class S;

template <typename T>
static inline std::true_type is_S_impl(const S<T>&);
static inline std::false_type is_S_impl(...);

template <typename T>
concept is_S = decltype(is_S_impl(std::declval<T>()))::value;


template <typename T>
struct S;

struct S_Base {
    template <typename V, typename U>
    requires is_S<V> && (!is_S<U>) && std::equality_comparable_with<typename
V::type, U>
    friend bool operator==(const V &v, const U &u) { return v.data == u; }
};

template <typename T>
struct S : private S_Base {
    using type = T;
    T data;

    S();
    explicit S(const T &);
};

void f() {
    S<int> s1; s1 == 123;
    S<double> s2; s2 == 123.4;
}

  parent reply	other threads:[~2021-12-11 16:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18  8:02 [Bug c++/102396] New: ICE when using concepts, in get, at cp/constraint.cc:2637 dangelog at gmail dot com
2021-09-27 12:51 ` [Bug c++/102396] [11/12 Regression] ICE when using concepts, in get, at cp/constraint.cc:2637 since r11-6245-g79f57d5cb070bb02 marxin at gcc dot gnu.org
2021-11-05 13:23 ` rguenth at gcc dot gnu.org
2021-11-05 14:01 ` ppalka at gcc dot gnu.org
2021-12-09 18:52 ` dangelog at gmail dot com
2021-12-09 18:54 ` dangelog at gmail dot com
2021-12-11 16:13 ` ppalka at gcc dot gnu.org [this message]
2021-12-13 16:58 ` dangelog at gmail dot com

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-102396-4-LAZBva9DD0@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).