User account creation filtered due to spam.

Bug 4403 - incorrect class becomes a friend in template
Summary: incorrect class becomes a friend in template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.1
: P3 normal
Target Milestone: 4.1.0
Assignee: Kriang Lerdsuwanakij
URL:
Keywords: monitored, patch, rejects-valid
Depends on: 1016
Blocks: 12944 9783 16995 17652
  Show dependency treegraph
 
Reported: 2001-09-26 09:06 UTC by Nathan Sidwell
Modified: 2005-03-14 14:53 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-26 18:42:26


Attachments
Patch for 4.1 (2.65 KB, patch)
2004-12-30 07:36 UTC, Kriang Lerdsuwanakij
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Sidwell 2001-09-26 09:06:00 UTC
during the cp-parser-branch development, I find that
g++.pt/inherit2.C makes the wrong class a friend.
We sued to give the correct diagnostic about
friend struct AC making ::AC a friend not A<T>::AC,
but infact we do make A<T>::AC the friend.

The test case did not check that friendliness was actually
bestowed. I have extended and XFAILED the testcase
on the cp-parser-branch.

Release:
CVS, 3.0.1, cp-parser-branch
Comment 1 Nathan Sidwell 2002-02-26 14:24:01 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed
Comment 2 Giovanni Bajo 2003-04-30 22:39:32 UTC
From: "Giovanni Bajo" <giovannibajo@libero.it>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<nathan@codesourcery.com>,
	<nobody@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>
Cc:  
Subject: Re: c++/4403: [2003-01-11]incorrect class becomes a friend in template
Date: Wed, 30 Apr 2003 22:39:32 +0200

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4403
 
 For easier reference, a minimal snippet showing this is:
 --------------------------------
 template <typename T>
 struct A
 {
     struct F;
 };
 
 template <typename T>
 struct B : A<T>
 {
     friend struct F;
 
 private:
     int priv;
 };
 
 struct F
 {
     void func(void)
     {
         B<int> b;
         b.priv = 0;
     }
 };
 --------------------------------
 pr4403.cpp: In member function `void F::func()':
 pr4403.cpp:13: error: `int B<int>::priv' is private
 pr4403.cpp:21: error: within this context
 
 Reconfirmed on any GCC version up to mainline 20030430.
 
 Giovanni Bajo
Comment 3 Andrew Pinski 2003-12-26 02:56:00 UTC
Even with trying to do:
friend struct ::F;
does not work.
Comment 4 Kriang Lerdsuwanakij 2004-12-30 07:36:03 UTC
Created attachment 7844 [details]
Patch for 4.1

Patch queued for 4.1.  Patch in PR1016 is the prerequisite
for this patch (due to pushtag, hidden_name_p changes).
Comment 5 Kriang Lerdsuwanakij 2005-03-13 16:47:31 UTC
Patch submitted:
  http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01294.html

This is simply the patch in the attachment to this PR retested with
explanation added.
Comment 6 CVS Commits 2005-03-14 14:52:24 UTC
Subject: Bug 4403

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	lerdsuwa@gcc.gnu.org	2005-03-14 14:51:25

Modified files:
	gcc/cp         : ChangeLog name-lookup.c pt.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.pt: inherit2.C 
Added files:
	gcc/testsuite/g++.dg/template: friend34.C friend35.C 

Log message:
	PR c++/4403
	PR c++/9783, DR433
	* name-lookup.c (pushtag): Skip template parameter scope when
	scope is ts_global.  Don't push tag into template parameter
	scope.
	* pt.c (instantiate_class_template): Reorder friend class
	template substitution to handle non-dependent friend class
	that hasn't been previously declared.
	
	* g++.dg/template/friend34.C: New test.
	* g++.dg/template/friend35.C: Likewise.
	* g++.old-deja/g++.pt/inherit2.C: Remove XFAIL's.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4662&r2=1.4663
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.112&r2=1.113
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.983&r2=1.984
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5161&r2=1.5162
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend34.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/friend35.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.pt/inherit2.C.diff?cvsroot=gcc&r1=1.7&r2=1.8

Comment 7 Kriang Lerdsuwanakij 2005-03-14 14:53:40 UTC
Fixed in the mainline.