This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ 2.95.2 disallows partially specialized friends
- To: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Subject: Re: g++ 2.95.2 disallows partially specialized friends
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Wed, 22 Mar 2000 15:11:01 -0700
- CC: gcc bug list <gcc-bugs at gcc dot gnu dot org>
Martin,
in case you're not subscribed, attached is my discussion with John Spicer on the
reflector. I hope this clarifies things.
Regards
Martin
- Subject: Re: declaring a partial specialization a friend
- From: "John H. Spicer" <jhs at edg dot com>
- Date: Wed, 22 Mar 2000 16:56:28 -0500
- Organization: Edison Design Group
- References: <38D9222C.9469AC32@roguewave.com> <38D92499.51BE3703@edg.com> <38D92B08.54D0B1A8@roguewave.com> <38D93018.336FAE42@edg.com> <38D93F71.C1533831@roguewave.com>
- Reply-To: c++std-core at research dot att dot com
- Transport-Options: /ignore
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
- Subject: Re: declaring a partial specialization a friend
- From: "John H. Spicer" <jhs at edg dot com>
- Date: Wed, 22 Mar 2000 15:42:00 -0500
- Organization: Edison Design Group
- References: <38D9222C.9469AC32@roguewave.com> <38D92499.51BE3703@edg.com> <38D92B08.54D0B1A8@roguewave.com>
- Reply-To: c++std-core at research dot att dot com
- Transport-Options: /ignore
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
- Subject: Re: declaring a partial specialization a friend
- From: "John H. Spicer" <jhs at edg dot com>
- Date: Wed, 22 Mar 2000 14:52:57 -0500
- Organization: Edison Design Group
- References: <38D9222C.9469AC32@roguewave.com>
- Reply-To: c++std-core at research dot att dot com
- Transport-Options: /ignore
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
- Subject: declaring a partial specialization a friend
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Wed, 22 Mar 2000 12:42:36 -0700
- Reply-To: c++std-core at research dot att dot com
- Transport-Options: /ignore
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