Here's the code sample: template<typename T> class Point; template<> class Point<double> { friend class Plane; double v; }; struct Plane { double get(const Point<double>& p); }; double Plane::get(const Point<double> &p) { return p.v; } Compiling this gives an error message: foo.cc: In member function `double Plane::get(constPoint<double>&)': foo.cc:7: error: `double Point<double>::v' is private foo.cc:14: error: within this context I can't find any justification for this error. The only odd thing about this code sample is that the friend declaration is the first time we have encountered the name "Plane", but this is legal. It even appears in one of the examples in clause 11.4 of the standard. Note that this error is very delicate. It goes away in the non-template case and it goes away if we use an impliict instantiation instead of an explicit specialization.
Confirmed, a regression from 2.95.3, looks related to PR 4403.
Retargeting to 3.4.1, being a regression on that release branch.
Working on a fix.
Subject: Bug 14930 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: mmitchel@gcc.gnu.org 2004-06-14 15:52:50 Modified files: gcc/cp : decl.c name-lookup.c ChangeLog gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: friend30.C ptrmem10.C Log message: PR c++/15096 * decl.c (grokdeclarator): Ignore pointer-to-members when computing template depth. PR c++/14930 * name-lookup.c (pushtag): Do not try to put class declarations in explicit specialization scopes. PR c++/15096 * g++.dg/template/ptrmem10.C: New test. PR c++/14930 * g++.dg/template/friend30.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1174.2.20&r2=1.1174.2.21 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.2.15&r2=1.34.2.16 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.122&r2=1.3892.2.123 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.206&r2=1.3389.2.207 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend30.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem10.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
Subject: Bug 14930 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-06-14 15:58:54 Modified files: gcc/cp : decl.c name-lookup.c ChangeLog gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: friend30.C ptrmem10.C Log message: PR c++/15096 * decl.c (grokdeclarator): Ignore pointer-to-members when computing template depth. PR c++/14930 * name-lookup.c (pushtag): Do not try to put class declarations in explicit specialization scopes. PR c++/15096 * g++.dg/template/ptrmem10.C: New test. PR c++/14930 * g++.dg/template/friend30.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1214&r2=1.1215 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.58&r2=1.59 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4094&r2=1.4095 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3854&r2=1.3855 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend30.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem10.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
Fixed in GCC 3.4.1.