The attached file tries several configuration of friend declaration. Some of them fails; I think these should behave identically to those not failing. arta:~/c/proba$ /gml/shared/gcc-3.0.2/bin/g++ -c specfriend.cc specfriend.cc:42: partial specialization `c<d<T> >' declared `friend' specfriend.cc:55: partial specialization `d<c<T> >' declared `friend' specfriend.cc:59: expected 1 levels of template parms for `class b::inner<I>', got 2 specfriend.cc:71: partial specialization `d<c<T> >' declared `friend' zsh: exit 1 /gml/shared/gcc-3.0.2/bin/g++ -c specfriend.cc arta:~/c/proba$ Release: 3.0.2 Environment: SuSE 7.1, i686
State-Changed-From-To: open->analyzed State-Changed-Why: This is not a bug in gcc. This is not legal code. When I compile with the Digital Unix C++ compiler, I get the following compilation errors: cxx: Error: specfriend.cc, line 67: "c" has already been declared in the current scope friend class c; -----------------^ cxx: Error: specfriend.cc, line 71: class "c" may not have a template argument list friend class d<c<T> >; -----------------^ cxx: Error: specfriend.cc, line 71: class "c" may not have a template argument list friend class d<c<T> >; -----------------^ cxx: Error: specfriend.cc, line 71: invalid partial specialization -- class "d<<error-type>>" is already fully specialized friend class d<c<T> >; ---------------^ cxx: Error: specfriend.cc, line 83: class "c" may not have a template argument list friend class c<d>; ---------------^ cxx: Info: 5 errors detected in the compilation of "specfriend.cc".
From: Martin Sebor <sebor@roguewave.com> To: gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/5094: partial specialisation cannot be friend?? Date: Wed, 12 Dec 2001 21:23:58 -0700 rodrigc@gcc.gnu.org wrote: > > Synopsis: partial specialisation cannot be friend?? > > State-Changed-From-To: open->analyzed > State-Changed-By: rodrigc > State-Changed-When: Wed Dec 12 19:58:51 2001 > State-Changed-Why: > This is not a bug in gcc. > This is not legal code. When I compile with > the Digital Unix C++ compiler, I get the > following compilation errors: Although I also have respect for the latest version of Compaq C++, it should be noted that the compiler isn't "the ultimate authority" on the validity of C++ code. What clenches it is that 14.5.3, p9 explicitly prohibits friend declarations of partial specializations: -9- Friend declarations shall not declare partial specializations. [Example: template<class T> class A { }; class X { template<class T> friend class A<T*>; // error }; 容nd example] Regards Martin
From: rodrigc@gcc.gnu.org To: benko@sztaki.hu, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: c++/5094: partial specialisation cannot be friend?? Date: 13 Dec 2001 03:58:51 -0000 Synopsis: partial specialisation cannot be friend?? State-Changed-From-To: open->analyzed State-Changed-By: rodrigc State-Changed-When: Wed Dec 12 19:58:51 2001 State-Changed-Why: This is not a bug in gcc. This is not legal code. When I compile with the Digital Unix C++ compiler, I get the following compilation errors: cxx: Error: specfriend.cc, line 67: "c" has already been declared in the current scope friend class c; -----------------^ cxx: Error: specfriend.cc, line 71: class "c" may not have a template argument list friend class d<c<T> >; -----------------^ cxx: Error: specfriend.cc, line 71: class "c" may not have a template argument list friend class d<c<T> >; -----------------^ cxx: Error: specfriend.cc, line 71: invalid partial specialization -- class "d<<error-type>>" is already fully specialized friend class d<c<T> >; ---------------^ cxx: Error: specfriend.cc, line 83: class "c" may not have a template argument list friend class c<d>; ---------------^ cxx: Info: 5 errors detected in the compilation of "specfriend.cc". http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=5094&database=gcc
From: Pal Benko <benko@sztaki.hu> To: rodrigc@gcc.gnu.org Cc: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org Subject: Re: c++/5094: partial specialisation cannot be friend?? Date: Fri, 14 Dec 2001 09:08:51 +0100 Thank you for the quick answer. > This is not a bug in gcc. > This is not legal code. When I compile with > the Digital Unix C++ compiler, I get the > following compilation errors: > > cxx: Error: specfriend.cc, line 67: "c" has already been declared in = the > current scope > friend class c; > -----------------^ Is template <> struct c<int> { class inner { friend class c<int>; }; template <typename T> friend class d<c<T> >; }; correct? gcc accepts it, but it also accepted the previous version. > cxx: Error: specfriend.cc, line 71: class "c" may not have a template > argument list > friend class d<c<T> >; > -----------------^ > cxx: Error: specfriend.cc, line 71: class "c" may not have a template > argument list > friend class d<c<T> >; > -----------------^ > cxx: Error: specfriend.cc, line 71: invalid partial specialization -- > class > "d<<error-type>>" is already fully specialized > friend class d<c<T> >; > ---------------^ OK, Martin Sebor gave the exact reference from the standard. > cxx: Error: specfriend.cc, line 83: class "c" may not have a template > argument list > friend class c<d>; > ---------------^ again: is template <> struct d<int> { template <int I> class inner { friend class d; }; friend class c<d<int> >; }; correct? gcc accepts, as previously. And there are three error messages of gcc not reproduced by the Digital Unix C++ in lines 42, 55 and 59 of the original bugreport. A simplified testcase: struct b { template <int I> class inner {}; }; template <typename T> struct c {}; template <typename T> struct c<T*> { class inner { friend class c; }; }; template <typename T> struct c<c<T> > { template <int I> class inner { friend class c; }; template <int I> friend class b::inner; }; Thanks again, Benko Pal=
Responsible-Changed-From-To: unassigned->lerdsuwa Responsible-Changed-Why: Patch submitted.
State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed in 3.3 and main trunk. Now only the template friend template <typename T> friend class d<c<T> >; is rejected. The rest is accepted.