Bug 14930 - [3.3/3.4/4.0 Regression] Friend declaration ignored
Summary: [3.3/3.4/4.0 Regression] Friend declaration ignored
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 3.4.1
Assignee: Mark Mitchell
URL:
Keywords: monitored, rejects-valid
Depends on:
Blocks:
 
Reported: 2004-04-12 22:54 UTC by Matt Austern
Modified: 2004-10-30 21:11 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3
Known to fail: 3.0.4 3.2.3 3.3.1 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2004-04-12 23:12:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Austern 2004-04-12 22:54:46 UTC
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.
Comment 1 Andrew Pinski 2004-04-12 23:12:38 UTC
Confirmed, a regression from 2.95.3, looks related to PR 4403.
Comment 2 Giovanni Bajo 2004-06-06 03:38:00 UTC
Retargeting to 3.4.1, being a regression on that release branch.
Comment 3 Mark Mitchell 2004-06-12 21:47:16 UTC
Working on a fix.
Comment 4 CVS Commits 2004-06-14 15:52:59 UTC
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

Comment 5 CVS Commits 2004-06-14 15:58:58 UTC
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

Comment 6 Mark Mitchell 2004-06-14 17:14:27 UTC
Fixed in GCC 3.4.1.