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 specializated friends
- To: sebor at my-Deja dot com, "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Subject: Re: g++ 2.95.2 disallows partially specializated friends
- From: " " <sebor at my-Deja dot com>
- Date: Wed, 22 Mar 2000 11:03:35 -0800
- Cc: gcc-bugs at gcc dot gnu dot org, pedretti at roguewave dot com
- Organization: My Deja Email (http://www.my-deja.com:80)
On Wed, 22 Mar 2000 01:16:30 Martin v. Loewis wrote:
>> g++ 2.95.s rejects friend declarations of partial class
>> specializations. I don't see anything in 14.5.3 that disallows this
>> (14.5.3, p1 says that "A friend of a class or class template can be
>> ... a specialization of a ... class template ...") - is this an
>> unimplemented feature, a bug, or have I missed something? (Other
>> conforming compilers such as edg 2.42 or HP aCC 3.14.10 accept the
>> code.)
>
>Thanks for your bug report. Without any deeper analysis: What exactly
>do you want this code to mean? If you want to make the global template
>a friend, then you can write
>
>template <class T, class U>
>struct A;
>
>
>template <class T>
>struct A<int, T>
>{
> class B {
> friend struct ::A;
> };
>};
According to 14.6.1, p2, "when the name of the template is neither qualified nor followed by <, it is equivalent to the name of the template followed by the template-arguments enclosed in <>." Here, ::A is qualified so the paragraph doesn't apply and since ::A is a template, not an ordinary struct, I'd say it's illegal (other compilers concur). Allowing g++ to accept this syntax is IMO either a nonconforming extension or a bug.
A valid declaration could look like this
template <class T>
struct A<int, T>
{
class B {
template <class U, class V>
friend struct A;
};
};
but this isn't what's intended. The intent is to make only specialiazations of A<int> a friend of A<int>::B. The friend declaration above makes *any* specialization of A<> a friend of A<int>::B.
>
>Without that, 'A' identifies the injected class name, which is the
>partial specialization. g++ rejects it on the basis of
>
> /* [temp.friend]
>
> Friend declarations shall not declare partial
> specializations. */
>
>Now, I this is certainly a declaration. What does it declare? A
>specialization? It certainly refers to one. If you don't think this
>answer is satisfying, please discuss the problem in comp.std.c++
>first.
Will do.
Thanks
Martin
>
>Regards,
>Martin
>
--== Sent via Deja.com http://www.deja.com/ ==--
Share what you know. Learn what you don't.