public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45942] New: class will not get friends with another class
@ 2010-10-08 13:42 MichieldeB at aim dot com
  2010-10-08 14:41 ` [Bug c++/45942] " redi at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-08 13:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

           Summary: class will not get friends with another class
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: MichieldeB@aim.com


In my current project, the construction of template class classB works well
when friend class declarations are replaced by making classA public.

With attempt 1, the compiler gives an error message, but not before
instantiation.

With attempt 2, the compiler gives an error message immediately, but an
incorrect one.


g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


template <class T, int C> class classA;

template <class T, int C, classA<T,C> &instanceA> class classB;

template <class T, int C> class classA
{

  // error message on instantiation: too few template parameters (1 < 3)
  template <classA &instanceA> friend class classB;

  // incorrect error message: partial specialization claimed but not apparent 
  // template <classA &instanceA> friend class classB<T,C,instanceA>;

private:
  int for_use_by_classB;

};

template <class T, int C, classA<T,C> &instanceA> class classB
{

  classB (int i) { instanceA.for_use_by_classB = i; }

};

// instantiation
// template class classA<char,128>;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
@ 2010-10-08 14:41 ` redi at gcc dot gnu.org
  2010-10-08 14:46 ` redi at gcc dot gnu.org
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-08 14:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-08 14:41:28 UTC ---
It's not entirely clear what you're saying is a bug, because your testcase
doesn't give any error.

It's more helpful to provide the source code that you claim produces the bug. 
I assume you this:

template <class T, int C> class classA;

template <class T, int C, classA<T,C> &instanceA> class classB;

template <class T, int C> class classA
{
  // incorrect error message: partial specialization claimed but not apparent 
  template <classA &instanceA> friend class classB<T,C,instanceA>;

private:
  int for_use_by_classB;

};

template <class T, int C, classA<T,C> &instanceA> class classB
{

  classB (int i) { instanceA.for_use_by_classB = i; }

};

// instantiation
template class classA<char,128>;


That code is not valid, the error is not incorrect.

You have declared classB as a friend, and as a template with one template
parameter, instanceA, and the template arguments <T,C,instanceA>. That is a
partial specialization.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
  2010-10-08 14:41 ` [Bug c++/45942] " redi at gcc dot gnu.org
@ 2010-10-08 14:46 ` redi at gcc dot gnu.org
  2010-10-08 14:51 ` MichieldeB at aim dot com
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-08 14:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-08 14:46:16 UTC ---
This variation uses B1 for your first attempt and B2 for your second attempt.

template <class T, int C> class A;

template <class T, int C, A<T,C> &a> class B1;

template <class T, int C, A<T,C> &a> class B2;

template <class T, int C> class A
{
  template <A &a> friend class B1;

  template <A &a> friend class B2<T,C,a>;
};

// instantiation
template class A<char,128>;


This code is not valid, G++ is correct to reject it.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
  2010-10-08 14:41 ` [Bug c++/45942] " redi at gcc dot gnu.org
  2010-10-08 14:46 ` redi at gcc dot gnu.org
@ 2010-10-08 14:51 ` MichieldeB at aim dot com
  2010-10-08 14:58 ` MichieldeB at aim dot com
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-08 14:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #3 from Michiel <MichieldeB at aim dot com> 2010-10-08 14:51:36 UTC ---
(In reply to comment #1)
> It's not entirely clear what you're saying is a bug, because your testcase
> doesn't give any error.
> 
> It's more helpful to provide the source code that you claim produces the bug. 
> I assume you this:
> 
> template <class T, int C> class classA;
> 
> template <class T, int C, classA<T,C> &instanceA> class classB;
> 
> template <class T, int C> class classA
> {
>   // incorrect error message: partial specialization claimed but not apparent 
>   template <classA &instanceA> friend class classB<T,C,instanceA>;
> 
> private:
>   int for_use_by_classB;
> 
> };
> 
> template <class T, int C, classA<T,C> &instanceA> class classB
> {
> 
>   classB (int i) { instanceA.for_use_by_classB = i; }
> 
> };
> 
> // instantiation
> template class classA<char,128>;
> 
> 
> That code is not valid, the error is not incorrect.
> 
> You have declared classB as a friend, and as a template with one template
> parameter, instanceA, and the template arguments <T,C,instanceA>. That is a
> partial specialization.

Apparently you are making the same mistake as the compiler. In the friend class
declaration, the third parameter is not free, indeed, but its specialization
level does not exceed that of the class definition of class classB. Thus the
friend declaration is no specialization in the proper relative sense. 

If you still do not agree, just provide code that makes classB a friend of
classA. That is what I want.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (2 preceding siblings ...)
  2010-10-08 14:51 ` MichieldeB at aim dot com
@ 2010-10-08 14:58 ` MichieldeB at aim dot com
  2010-10-08 15:03 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-08 14:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

Michiel <MichieldeB at aim dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #4 from Michiel <MichieldeB at aim dot com> 2010-10-08 14:58:42 UTC ---
(In reply to comment #2)
> This variation uses B1 for your first attempt and B2 for your second attempt.
> 
> template <class T, int C> class A;
> 
> template <class T, int C, A<T,C> &a> class B1;
> 
> template <class T, int C, A<T,C> &a> class B2;
> 
> template <class T, int C> class A
> {
>   template <A &a> friend class B1;
> 
>   template <A &a> friend class B2<T,C,a>;
> };
> 
> // instantiation
> template class A<char,128>;
> 
> 
> This code is not valid, G++ is correct to reject it.

Please explain why the code is invalid, and do not click "Resolved invalid"
until ClassB is a friend of ClassA.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (3 preceding siblings ...)
  2010-10-08 14:58 ` MichieldeB at aim dot com
@ 2010-10-08 15:03 ` paolo.carlini at oracle dot com
  2010-10-08 15:08 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-08 15:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |paolo.carlini at oracle dot
                   |                            |com
         Resolution|                            |INVALID

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-08 15:02:54 UTC ---
(In reply to comment #3)
> Apparently you are making the same mistake as the compiler.

Before adjusting the sentence to use a proper plural here (the same error
happens with the Intel, EDG, Comeau, SunStudio and Microsoft compilers, for
sure) I would suggest considering a little longer the first person singular.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (4 preceding siblings ...)
  2010-10-08 15:03 ` paolo.carlini at oracle dot com
@ 2010-10-08 15:08 ` redi at gcc dot gnu.org
  2010-10-08 15:12 ` MichieldeB at aim dot com
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-08 15:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-08 15:08:36 UTC ---
(In reply to comment #4)
> (In reply to comment #2)
> > This code is not valid, G++ is correct to reject it.
> 
> Please explain why the code is invalid, and do not click "Resolved invalid"
> until ClassB is a friend of ClassA.

You reported an invalid bug, so I rejected it.
It's not my job to teach you C++ but here you go:

template <class T, int C> class A;

template <class T, int C, A<T,C> &a> class B;

template <class T, int C> class A
{
  template <class X, int Y, A<X,Y>&> friend class B;
};


That makes B<X,Y,A<X,Y>&> a friend of A

Your original example is invalid for the reason the compiler gave, the syntax
you tried to use declares a partial specialization, which is not allowed in a
friend declaration.  That's how C++ works, I don't make the rules.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (5 preceding siblings ...)
  2010-10-08 15:08 ` redi at gcc dot gnu.org
@ 2010-10-08 15:12 ` MichieldeB at aim dot com
  2010-10-08 15:36 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-08 15:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #7 from Michiel <MichieldeB at aim dot com> 2010-10-08 15:12:36 UTC ---
(In reply to comment #5)
> (In reply to comment #3)
> > Apparently you are making the same mistake as the compiler.
> 
> Before adjusting the sentence to use a proper plural here (the same error
> happens with the Intel, EDG, Comeau, SunStudio and Microsoft compilers, for
> sure) I would suggest considering a little longer the first person singular.

Does C++ accept dependencies between template parameters. G++ does that within
my project. And all I am asking is to make ClassB a friend of ClassA before
clicking "Resolved Invalid". I am using G++ and do not see a reason why another
compiler should be able to make ClassB a friend of ClassA.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (6 preceding siblings ...)
  2010-10-08 15:12 ` MichieldeB at aim dot com
@ 2010-10-08 15:36 ` redi at gcc dot gnu.org
  2010-10-08 15:43 ` MichieldeB at aim dot com
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-08 15:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-08 15:36:01 UTC ---
(In reply to comment #7)
> (In reply to comment #5)
> > (In reply to comment #3)
> > > Apparently you are making the same mistake as the compiler.
> > 
> > Before adjusting the sentence to use a proper plural here (the same error
> > happens with the Intel, EDG, Comeau, SunStudio and Microsoft compilers, for
> > sure) I would suggest considering a little longer the first person singular.
> 
> Does C++ accept dependencies between template parameters. G++ does that within
> my project. And all I am asking is to make ClassB a friend of ClassA before
> clicking "Resolved Invalid".

You seem to misunderstand what this bugzilla is for.  You reported a bug, but
it was invalid, so it doesn't belong in this bugzilla.  Whether you know a
workaround or not is irrelevant.  You have not found a bug in the compiler. 
Figuring out what's wrong with your code and fixing it is your job, not GCC's.

"Resolved - Invalid" means it's not a valid bug report, it doesn't mean "We
have analysed the user's code and shown how to fix it"

> I am using G++ and do not see a reason why another
> compiler should be able to make ClassB a friend of ClassA.

Other compilers don't accept your code either, because it's wrong.

However, I have given you a workaround that makes classB a friend of classA, so
you should be happy now, right?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (7 preceding siblings ...)
  2010-10-08 15:36 ` redi at gcc dot gnu.org
@ 2010-10-08 15:43 ` MichieldeB at aim dot com
  2010-10-08 15:59 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-08 15:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #9 from Michiel <MichieldeB at aim dot com> 2010-10-08 15:43:13 UTC ---
(In reply to comment #6)
> (In reply to comment #4)
> > (In reply to comment #2)
> > > This code is not valid, G++ is correct to reject it.
> > 
> > Please explain why the code is invalid, and do not click "Resolved invalid"
> > until ClassB is a friend of ClassA.
> 
> You reported an invalid bug, so I rejected it.
> It's not my job to teach you C++ but here you go:
> 
> template <class T, int C> class A;
> 
> template <class T, int C, A<T,C> &a> class B;
> 
> template <class T, int C> class A
> {
>   template <class X, int Y, A<X,Y>&> friend class B;
> };
> 
> 
> That makes B<X,Y,A<X,Y>&> a friend of A
> 
> Your original example is invalid for the reason the compiler gave, the syntax
> you tried to use declares a partial specialization, which is not allowed in a
> friend declaration.  That's how C++ works, I don't make the rules.

I really tried everything, but I have to admit I missed that one. Sorry. But
you have to admit that it is a rather unnatural way to make friends. 
Furthermore, the third parameter Z is missing (I would prefer A<X,Y>&Z), but
that does not seem to be a problem for the compiler.

Thus it seems that the bug is that c++ is designed is such a way that it gives
error messages which are incorrect.

If you would have followed the title of my bug report immediately instead of
saying that is was invalid, then the discussion would have been unnecessary.

Now it is still odd that the first attempt gives an error so lately. The
template precompiler counts three arguments and the template instantiator
counts one, which is not very consistent.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (8 preceding siblings ...)
  2010-10-08 15:43 ` MichieldeB at aim dot com
@ 2010-10-08 15:59 ` redi at gcc dot gnu.org
  2010-10-08 16:09 ` MichieldeB at aim dot com
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-08 15:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-08 15:59:08 UTC ---
(In reply to comment #9)
> 
> I really tried everything, but I have to admit I missed that one. Sorry. But
> you have to admit that it is a rather unnatural way to make friends. 
> Furthermore, the third parameter Z is missing (I would prefer A<X,Y>&Z), but
> that does not seem to be a problem for the compiler.

You can just add it if it makes you feel better. That parameter isn't used in
the friend declaration, so giving it a name is optional.  YOu can call it Z or
whatever you want, it doesn't matter.

> Thus it seems that the bug is that c++ is designed is such a way that it gives
> error messages which are incorrect.

C++ doesn't specify the text of error messages, it says what is valid and what
is not.  The compiler rejected your code because it's not valid.

I don't know why you think the error message is incorrect.

This is a template declaration:
  template <classA &instanceA> friend class classB;
It has one parameter.
classB was already declared as a template with three parameters.
So you get this error message:

pr45942.cc:9:45: error: redeclared with 1 template parameter
pr45942.cc:3:57: note: previous declaration ‘template<class T, int C, classA<T,
C>& instanceA> class classB’ used 3 template parameters

That seems correct to me.

> If you would have followed the title of my bug report immediately instead of
> saying that is was invalid, then the discussion would have been unnecessary.

But your bug report IS invalid.
I repeat, you said there was a bug in the compiler, I said there isn't.

If you had said "please help me fix my code" that would have been a different
discussion (and you'd have been asked to go somewhere else, like a C++ forum or
newsgroup)

Despite that, you have succeeded in turning it into a discussion of why your
code is not valid.

> Now it is still odd that the first attempt gives an error so lately. The
> template precompiler counts three arguments and the template instantiator
> counts one, which is not very consistent.

There's no "template precompiler"

Please take this somewhere else, GCC's bugzilla is not the place for it.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (9 preceding siblings ...)
  2010-10-08 15:59 ` redi at gcc dot gnu.org
@ 2010-10-08 16:09 ` MichieldeB at aim dot com
  2010-10-09 13:02 ` MichieldeB at aim dot com
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-08 16:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #11 from Michiel <MichieldeB at aim dot com> 2010-10-08 16:09:33 UTC ---
C++ is designed to give an error message which is syntactically correct, but
semantically incorrect.

I thought that the template prechecker (preprocessor or whatever, do not
correct me this time) counted template arguments in friend declarations, but
now it seems it does not, sorry.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (10 preceding siblings ...)
  2010-10-08 16:09 ` MichieldeB at aim dot com
@ 2010-10-09 13:02 ` MichieldeB at aim dot com
  2010-10-09 13:38 ` MichieldeB at aim dot com
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-09 13:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #12 from Michiel <MichieldeB at aim dot com> 2010-10-09 13:02:51 UTC ---
> You seem to misunderstand what this bugzilla is for. 

No, that is not true, although the effect has been equally terrible. Indeed,
you only need to say that my bug is invalid.

However, it is common in many forms of written communication that one assures
him/herself that the other has read and understood everything. Maybe I should
have assumed that this was the case, but reacting on one out of three issues in
my bug report was not very convincing in this matter.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (11 preceding siblings ...)
  2010-10-09 13:02 ` MichieldeB at aim dot com
@ 2010-10-09 13:38 ` MichieldeB at aim dot com
  2010-10-09 18:08 ` redi at gcc dot gnu.org
  2010-10-09 18:19 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: MichieldeB at aim dot com @ 2010-10-09 13:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #13 from Michiel <MichieldeB at aim dot com> 2010-10-09 13:38:05 UTC ---
The reason that I did not succeed in making ClassB a friend of ClassA is that
C++ is not very logical. See below.


template <class T, int C> class classB;
template <class T, int C, class V> class classC;

template <class T, int C> class classA
{

  // classA<char,128> does NOT become friends with classA<short,512>
  friend class classB<T,C>;

  // with an extra template argument, this is only possible via 
  // specialization, which is not allowed
  template <> friend class classB<T,C>;
  template <class V> friend class classC<T,C,V>;

  // because with your solution, classA<char,128> (classB<char,128,short>)
  // DOES become friends with classA<short,512> (classB<short,512,short>)
  template <class TT, int CC> friend class classB;
  template <class TT, int CC, class VV> friend class classC;

};

template class classA<char,128>;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (12 preceding siblings ...)
  2010-10-09 13:38 ` MichieldeB at aim dot com
@ 2010-10-09 18:08 ` redi at gcc dot gnu.org
  2010-10-09 18:19 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-09 18:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-09 18:07:42 UTC ---
(In reply to comment #13)
> The reason that I did not succeed in making ClassB a friend of ClassA is that
> C++ is not very logical.

Maybe so, but that's not a bug in GCC.

The next version of C++ is more lenient in what is allowed in a friend
declaration and I think it is possible to declare a typedef as a friend so you
could create a class template with a nested member and declare that member as a
friend.  That template could be specialized to make certain specializations of
classB a friend:

template<class T, int C, class AA>
struct Befriender {
  typedef int type;
};

template<class T, int C>
struct Befriender<T, C, A<T,C>> {
  typedef B<T,C,A<T,C>&> type;
};

template<class T, int C>
class A {
  friend typename Befriender<T,C,A>::type;
};

I *think* this would work, when Befriender::type results in "friend int" it is
ignored, without error.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/45942] class will not get friends with another class
  2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
                   ` (13 preceding siblings ...)
  2010-10-09 18:08 ` redi at gcc dot gnu.org
@ 2010-10-09 18:19 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-09 18:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-09 18:18:56 UTC ---
you don't even need the partial specialization of Befriender:

template<class, int> class A;
template<class T, int C, A<T,C>&> class A;

template<class T, int C>
struct Befriender {
  typedef B<T,C,A<T,C>&> type;
};

template<class T, int C> class A
{
  friend typename Befriender<T,C,A>::type;
};

(I can't test this now, so it might be wrong, and it definitely isn't allowed
in C++03)


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-10-09 18:19 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-08 13:42 [Bug c++/45942] New: class will not get friends with another class MichieldeB at aim dot com
2010-10-08 14:41 ` [Bug c++/45942] " redi at gcc dot gnu.org
2010-10-08 14:46 ` redi at gcc dot gnu.org
2010-10-08 14:51 ` MichieldeB at aim dot com
2010-10-08 14:58 ` MichieldeB at aim dot com
2010-10-08 15:03 ` paolo.carlini at oracle dot com
2010-10-08 15:08 ` redi at gcc dot gnu.org
2010-10-08 15:12 ` MichieldeB at aim dot com
2010-10-08 15:36 ` redi at gcc dot gnu.org
2010-10-08 15:43 ` MichieldeB at aim dot com
2010-10-08 15:59 ` redi at gcc dot gnu.org
2010-10-08 16:09 ` MichieldeB at aim dot com
2010-10-09 13:02 ` MichieldeB at aim dot com
2010-10-09 13:38 ` MichieldeB at aim dot com
2010-10-09 18:08 ` redi at gcc dot gnu.org
2010-10-09 18:19 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).