Bug 5094 - partial specialisation cannot be friend??
Summary: partial specialisation cannot be friend??
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.2
: P3 normal
Target Milestone: 3.3
Assignee: Kriang Lerdsuwanakij
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2001-12-12 07:26 UTC by benko
Modified: 2005-06-18 23:51 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
specfriend.cc (175 bytes, application/octet-stream)
2003-05-21 15:16 UTC, benko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description benko 2001-12-12 07:26:01 UTC
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
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<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".
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 T> class A { };
           class X {
               template<class T> 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<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

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<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=
 
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 <typename T> friend class d<c<T> >;
    is rejected.  The rest is accepted.