5094 – partial specialisation cannot be friend?? (original) (raw)

| 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 >' declared `friend' specfriend.cc:55: partial specialization `d<c >' declared `friend' specfriend.cc:59: expected 1 levels of template parms for `class b::inner', got 2 specfriend.cc:71: partial specialization `d<c >' 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 Comment 1 Craig Rodrigues 2001-12-12 19:58:51 UTC 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 >; -----------------^ cxx: Error: specfriend.cc, line 71: class "c" may not have a template argument list friend class d<c >; -----------------^ cxx: Error: specfriend.cc, line 71: invalid partial specialization -- class "d<>" is already fully specialized friend class d<c >; ---------------^ cxx: Error: specfriend.cc, line 83: class "c" may not have a template argument list friend class c; ---------------^ cxx: Info: 5 errors detected in the compilation of "specfriend.cc". Comment 2 Martin Sebor 2001-12-12 21:23:58 UTC 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 A { }; class X { template friend class A<T*>; // error }; 容nd example] Regards Martin Comment 3 Craig Rodrigues 2001-12-13 03:58:51 UTC 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 >; -----------------^ cxx: Error: specfriend.cc, line 71: class "c" may not have a template argument list friend class d<c >; -----------------^ cxx: Error: specfriend.cc, line 71: invalid partial specialization -- class "d<>" is already fully specialized friend class d<c >; ---------------^ cxx: Error: specfriend.cc, line 83: class "c" may not have a template argument list friend class c; ---------------^ 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 Comment 4 benko 2001-12-14 09:08:51 UTC 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 { class inner { friend class c; }; template friend class d<c >; }; 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 >; > -----------------^ > cxx: Error: specfriend.cc, line 71: class "c" may not have a template > argument list > friend class d<c >; > -----------------^ > cxx: Error: specfriend.cc, line 71: invalid partial specialization -- > class > "d<>" is already fully specialized > friend class d<c >; > ---------------^ 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; > ---------------^ again: is template <> struct d { template class inner { friend class d; }; friend class c<d >; }; 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 class inner {}; }; template struct c {}; template struct c<T*> { class inner { friend class c; }; }; template struct c<c > { template class inner { friend class c; }; template friend class b::inner; }; Thanks again, Benko Pal= Comment 5 Kriang Lerdsuwanakij 2002-11-27 05:52:15 UTC Responsible-Changed-From-To: unassigned->lerdsuwa Responsible-Changed-Why: Patch submitted. Comment 6 Kriang Lerdsuwanakij 2002-12-19 07:36:45 UTC State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed in 3.3 and main trunk. Now only the template friend template friend class d<c >; is rejected. The rest is accepted. | | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |