public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "andebjor at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96673] New: Friend class with templates and default constructor not recognized in C++14 or later Date: Tue, 18 Aug 2020 10:16:01 +0000 [thread overview] Message-ID: <bug-96673-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96673 Bug ID: 96673 Summary: Friend class with templates and default constructor not recognized in C++14 or later Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: andebjor at gmail dot com Target Milestone: --- This code fails when compiled as C++14 or C++17 with the error message "error: 'C<T>::C(A<T>&) [with T = int]' is private within this context". ---8<--- template <class T> class A {}; template <class T> class B; template <class T> class C { private: friend class B<T>; explicit C(A<T>&) {}; }; template <class T> class B { public: B() = default; //B() {}; // << This implementation of the constructor makes it work A<T> a = {}; C<T> c = C<T>{a}; }; int main() { auto b = B<int>{}; auto &c = b.c; } --->8--- Compiler explorer link: https://godbolt.org/z/4ofMdM This code builds with `clang` but fails with most versions of GCC. * Version 4.9 works * Version 5.x: internal compiler error * Version 6.x up until trunk version: "C<T>::C(A<T>&) [with T = int]' is private within this context" There are several ways to make the code build: * Removing templating. Without templates the error about the constructor being private does not appear. * Changing the constructor of `B` from `B() = default;` to `B() {};` * Building with C++11.
next reply other threads:[~2020-08-18 10:16 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-18 10:16 andebjor at gmail dot com [this message] 2020-08-18 16:08 ` [Bug c++/96673] [8/9/10/11 Regression] " mpolacek at gcc dot gnu.org 2020-08-18 16:18 ` mpolacek at gcc dot gnu.org 2020-10-12 12:32 ` rguenth at gcc dot gnu.org 2021-04-06 19:00 ` jason at gcc dot gnu.org 2021-04-06 20:42 ` cvs-commit at gcc dot gnu.org 2021-04-06 20:42 ` [Bug c++/96673] [8/9/10 " jason at gcc dot gnu.org 2021-05-14 9:53 ` [Bug c++/96673] [9/10 " jakub at gcc dot gnu.org 2021-05-20 21:35 ` cvs-commit at gcc dot gnu.org 2021-06-01 8:18 ` rguenth at gcc dot gnu.org 2022-05-13 17:41 ` [Bug c++/96673] [9 " cvs-commit at gcc dot gnu.org 2022-05-13 17:44 ` jason 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-96673-4@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: linkBe 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).