Bug 5369 - template member friend declaration not honored
Summary: template member friend declaration not honored
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.1
: P3 normal
Target Milestone: 3.4.0
Assignee: Kriang Lerdsuwanakij
URL:
Keywords: monitored, patch, rejects-valid
Depends on:
Blocks: 7818 10694
  Show dependency treegraph
 
Reported: 2002-01-13 13:36 UTC by Martin Sebor
Modified: 2003-11-22 06:50 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-06-23 11:21:38


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2002-01-13 13:36:01 UTC
I believe this program is well-formed. It fails to compile
with 3.0.1.

Regards
Martin

$ cat t.cpp ;  g++ t.cpp
template <class T>
struct S
{
    int foo () {
        return S<int>::bar ();
    }

private:

    template <class U>
    friend int S<U>::foo ();

    static int bar () { return 0; }
};

int main ()
{
    S<char>().foo ();
}
t.cpp: In member function `int S<T>::foo() [with T = char]':
t.cpp:18:   instantiated from here
t.cpp:13: `static int S<T>::bar() [with T = int]' is private
t.cpp:5: within this context

Release:
3.0.1
Comment 1 Kriang Lerdsuwanakij 2002-06-08 07:57:22 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.
Comment 2 Kriang Lerdsuwanakij 2002-12-19 08:12:42 UTC
Responsible-Changed-From-To: unassigned->lerdsuwa
Responsible-Changed-Why: Relate to PR7641.
Comment 3 Kriang Lerdsuwanakij 2003-08-11 14:49:46 UTC
Patch submitted:
  http://gcc.gnu.org/ml/gcc-patches/2003-08/msg00644.html
Comment 4 Kriang Lerdsuwanakij 2003-09-12 15:10:37 UTC
Revised patch:
  http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00783.html
Comment 5 GCC Commits 2003-11-22 06:49:25 UTC
Subject: Bug 5369

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	lerdsuwa@gcc.gnu.org	2003-11-22 06:49:22

Modified files:
	gcc/cp         : ChangeLog cp-tree.h decl.c decl2.c friend.c 
	                 pt.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.pt: friend44.C 
Added files:
	gcc/testsuite/g++.dg/template: memfriend1.C memfriend2.C 
	                               memfriend3.C memfriend4.C 
	                               memfriend5.C memfriend6.C 
	                               memfriend7.C memfriend8.C 

Log message:
	PR c++/5369
	* friend.c (is_friend): Handle member function of a class
	template as template friend.
	(do_friend): Likewise.
	* decl2.c (check_classfn): Add template_header_p parameter.
	* decl.c (start_decl): Adjust check_classfn call.
	(grokfndecl): Likewise.
	* pt.c (is_specialization_of_friend): New function.
	(uses_template_parms_level): Likewise.
	(push_template_decl_real): Use uses_template_parms_level.
	(tsubst_friend_function): Adjust check_classfn call.
	* cp-tree.h (check_classfn): Adjust declaration.
	(uses_template_parms_level): Add declaration.
	(is_specialization_of_friend): Likewise.
	
	* g++.dg/template/memfriend1.C: New test.
	* g++.dg/template/memfriend2.C: Likewise.
	* g++.dg/template/memfriend3.C: Likewise.
	* g++.dg/template/memfriend4.C: Likewise.
	* g++.dg/template/memfriend5.C: Likewise.
	* g++.dg/template/memfriend6.C: Likewise.
	* g++.dg/template/memfriend7.C: Likewise.
	* g++.dg/template/memfriend8.C: Likewise.
	* g++.old-deja/g++.pt/friend44.C: Remove a bogus error.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3770&r2=1.3771
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.933&r2=1.934
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1156&r2=1.1157
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.686&r2=1.687
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/friend.c.diff?cvsroot=gcc&r1=1.91&r2=1.92
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.795&r2=1.796
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3202&r2=1.3203
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend7.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend8.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/friend44.C.diff?cvsroot=gcc&r1=1.2&r2=1.3

Comment 6 Kriang Lerdsuwanakij 2003-11-22 06:50:48 UTC
Fixed in the mainline.