public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/102995] Template friend class declaration of same class with different template parameters fails to allow private methods access
Date: Sun, 31 Oct 2021 02:22:33 +0000	[thread overview]
Message-ID: <bug-102995-4-EaGeE5d8iU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102995-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> I suspect the original testcase is invalid code and clang is incorrect in
> accepting it.

You can limit the friendship to only the operator== that have the same second
template operand if you need to limit the friendship slightly more:
template<typename A, typename B> class First {
  public:
    First() = default;

  private:
    int GetId() const {
      return 1;
    }
    template<typename U, typename D>
    friend bool operator==(const First<U, B>& lhs,
                           const First<D, B>& rhs);
};
template<typename U, typename D, typename V>
bool operator==(const First<U, V>& lhs,
                const First<D, V>& rhs) {
                             return lhs.GetId() == rhs.GetId();
                           }
int main() {
  First<int, bool> a;
  First<void *, bool> b;

  return a == b;
}

  parent reply	other threads:[~2021-10-31  2:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29  7:33 [Bug c++/102995] New: " jdapena at igalia dot com
2021-10-31  2:05 ` [Bug c++/102995] " pinskia at gcc dot gnu.org
2021-10-31  2:15 ` pinskia at gcc dot gnu.org
2021-10-31  2:22 ` pinskia at gcc dot gnu.org [this message]
2021-11-02  9:18 ` jdapena at igalia dot com
2023-11-16 15:58 ` ppalka 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-102995-4-EaGeE5d8iU@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).