From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CA6393858D38; Tue, 18 Aug 2020 10:16:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA6393858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597745761; bh=OC1sGG/7h1Jp+8SZ0ybJSmLKi1l5S3hXYGfA3LKW0yA=; h=From:To:Subject:Date:From; b=NJnDeGXApPjQ6VHUqQtIVgXkD+2VPCcKeRVIrs4pTeTWkxlfN+r2SNmAhJ3dS6BWT 4c4lY08+koxHG2OikQNWlB7z3ZYFjPFax5FnhlOJOr2iiD/swlYi4RbXJyFRgafLyi XPdzP6y6Kg6GC0AEw9dMV2NeNXtSCn/jlG87MbyI= From: "andebjor at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andebjor at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Aug 2020 10:16:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96673 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 "err= or: 'C::C(A&) [with T =3D int]' is private within this context". ---8<--- template class A {}; template class B; template class C { private: friend class B; explicit C(A&) {}; }; template class B { public: B() =3D default; //B() {}; // << This implementation of the constructor makes it w= ork A a =3D {}; C c =3D C{a}; }; int main() { auto b =3D B{}; auto &c =3D 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::C(A&) [with T =3D int]' is private within this context" There are several ways to make the code build: * Removing templating. Without templates the error about the constructor be= ing private does not appear. * Changing the constructor of `B` from `B() =3D default;` to `B() {};` * Building with C++11.=