This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: g++ 2.95.2 disallows partially specialized friends


Martin,

in case you're not subscribed, attached is my discussion with John Spicer on the
reflector. I hope this clarifies things.

Regards
Martin


To: C++ core language mailing list
Message c++std-core-8613

Martin Sebor wrote:

> > If this were not enough, there is also the wording in 14.5.3p4 that says
> > "A template friend declaration specifies that all specializations of that template,
> > whether they are implicitly instantiated, partially specialized, or explicitly
> > specialized are friend of the class containing the friend declaration.".
> >
> > This directly contradicts the interpretation that you mention.
> 
> I don't think that p4 applies to the friend declaration in my example since the
> paragraph talks about template friend declarations. But even if it did, I fail
> to see the contradiction. All the paragraph says is that a template friend
> declaration makes every specialization generated from that template a friend. It
> doesn't say that the friend declaration itself can limit the scope of
> specializations to which it grants friendship by referring to a partial
> specialization.
> 

It explicitly says that a partial specialization can be a friend, which
contradicts the asserted meaning of the text in question.

John Spicer
Edison Design Group




To: C++ core language mailing list
Message c++std-core-8611

Martin Sebor wrote:
> 
> To: C++ core language mailing list
> Message c++std-core-8610
> 
> "John H. Spicer" wrote:
> >
> > To: C++ core language mailing list
> > Message c++std-core-8608
> >
> ...
> >
> > The wording you quote is intended to prohibit the following:
> >
> >         template <class T> struct A {};
> >         class X {
> >                 template <class T> friend struct A<T*>;
> >         };
> >
> > This example is in the standard as part of the paragraph you quote.
> 
> Yes, I've seen the example. The issue is that the paragraph could be interpreted
> as meaning that no partial specialization can be made a friend. g++ for instance
> rejects the code and the position of the compiler writer is that 14.5.3, p9,
> says it's disallowed. If that is not the intent as you seem to suggest it is not
> IMO stated with sufficient clarity.

I have a hard time reading it to say anything other than what the example
illustrates.

In particular, I don't understand how "friend struct A;" could be taken
as a declaration of a partial specialization, as a partial specialization
is a form of template declaration, and the friend declaration in question
is not a template declaration.

I don't think it is reasonable to interpret "Friend declarations shall not
declare partial specializations" to mean "Friend declarations shall not
refer to classes generated from partial specializations.".  Particularly
given the definition of partial specialization which is given a few lines
later.

If this were not enough, there is also the wording in 14.5.3p4 that says
"A template friend declaration specifies that all specializations of that template,
whether they are implicitly instantiated, partially specialized, or explicitly
specialized are friend of the class containing the friend declaration.".

This directly contradicts the interpretation that you mention.

John Spicer
Edison Design Group

> 
> Martin
> 
> >
> > John Spicer
> > Edison Design Group
> >
> > >
> > > template <class T, class U>
> > > struct A;
> > >
> > > template <class T>
> > > struct A<int, T>
> > > {
> > >     class B {
> > >         friend struct A;   // A<int, T> is a partial spec.
> > >     };
> > > };
> > >
> > > Thanks
> > > Martin




To: C++ core language mailing list
Message c++std-core-8608

Martin Sebor wrote:
> 
> To: C++ core language mailing list
> Message c++std-core-8607
> 
> 14.5.3 - Friends [temp.friend], p9, says that "Friend declarations shall not
> declare partial specializations.". Is the intent of this restriction that the
> code below be illegal?
> 
> If not, then I think the wording should be changed to say "Friend declarations
> shall not first declare partial specializations." to make it clear that
> declaring a partial specialization a friend is allowed as long as declaration
> doesn't constitute an injection.
> 
> In either case I think an additional example such as the one below would make
> things clearer.

The wording you quote is intended to prohibit the following:

	template <class T> struct A {};
	class X {
		template <class T> friend struct A<T*>;
	};

This example is in the standard as part of the paragraph you quote.

John Spicer
Edison Design Group


> 
> template <class T, class U>
> struct A;
> 
> template <class T>
> struct A<int, T>
> {
>     class B {
>         friend struct A;   // A<int, T> is a partial spec.
>     };
> };
> 
> Thanks
> Martin




To: C++ core language mailing list
Message c++std-core-8607

14.5.3 - Friends [temp.friend], p9, says that "Friend declarations shall not
declare partial specializations.". Is the intent of this restriction that the
code below be illegal?

If not, then I think the wording should be changed to say "Friend declarations
shall not first declare partial specializations." to make it clear that
declaring a partial specialization a friend is allowed as long as declaration
doesn't constitute an injection.

In either case I think an additional example such as the one below would make
things clearer.

template <class T, class U>
struct A;

template <class T>
struct A<int, T>
{
    class B {
        friend struct A;   // A<int, T> is a partial spec.
    };
};


Thanks
Martin



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]