c++/5094: partial specialisation cannot be friend??

Pal Benko benko@sztaki.hu
Fri Dec 14 01:27:00 GMT 2001


>From benko Fri Dec 14 09: 08 MET 2001
References: <20011213035851.697.qmail@sources.redhat.com>

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


More information about the Gcc-bugs mailing list