public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26543]  New: friend class declaration inside class scope ignored
@ 2006-03-03 10:03 pato101 at gmail dot com
  2006-03-03 11:42 ` [Bug c++/26543] " rguenth at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: pato101 at gmail dot com @ 2006-03-03 10:03 UTC (permalink / raw)
  To: gcc-bugs

Seems that "class" is ignored at "friend class a" within class definition
scope. This makes some code I have around not to compile. I may perhaps include
a file with all the classes available at the beginning... but it is ugly.
Nowadays I'm using gcc-3.4 instead of gcc-4.x

See below example of code that fails with gcc version >= 4.0


--8<---- demo.cpp, please do g++ -c demo.cpp -----8<--8<
class a;
//class c;  // If uncommented, the code compiles. Otherwise it does not!
class b
{
friend class a;
friend class c;
        a * aa;
        c * cc;
private:
        float p;
};

class a {
        b bb;
        void bp() { float f = bb.p; };
};

class c {
        b bb;
        void bp() { float f = bb.p; };
};
-->8---- demo.cpp, please do g++ -c demo.cpp ----->8-->8


-- 
           Summary: friend class declaration inside class scope ignored
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pato101 at gmail dot com


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


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

* [Bug c++/26543] friend class declaration inside class scope ignored
  2006-03-03 10:03 [Bug c++/26543] New: friend class declaration inside class scope ignored pato101 at gmail dot com
@ 2006-03-03 11:42 ` rguenth at gcc dot gnu dot org
  2006-03-03 13:44 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-03-03 11:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2006-03-03 11:42 -------
This is invalid C++.  Use -ffriend-injection to make it work.


-- 

rguenth at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26543] friend class declaration inside class scope ignored
  2006-03-03 10:03 [Bug c++/26543] New: friend class declaration inside class scope ignored pato101 at gmail dot com
  2006-03-03 11:42 ` [Bug c++/26543] " rguenth at gcc dot gnu dot org
@ 2006-03-03 13:44 ` pinskia at gcc dot gnu dot org
  2006-03-03 14:26 ` pato101 at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-03 13:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-03-03 13:44 -------
(In reply to comment #1)
> Use -ffriend-injection to make it work.

Note -ffriend-injection will not work in this case as -ffriend-injection is
only for friend functions and not for friend classes.
Anyways this is all documented on the changes page for 4.0.
http://gcc.gnu.org/gcc-4.0/changes.html


-- 


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


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

* [Bug c++/26543] friend class declaration inside class scope ignored
  2006-03-03 10:03 [Bug c++/26543] New: friend class declaration inside class scope ignored pato101 at gmail dot com
  2006-03-03 11:42 ` [Bug c++/26543] " rguenth at gcc dot gnu dot org
  2006-03-03 13:44 ` pinskia at gcc dot gnu dot org
@ 2006-03-03 14:26 ` pato101 at gmail dot com
  2006-03-03 14:29 ` pinskia at gcc dot gnu dot org
  2006-03-03 14:39 ` pato101 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pato101 at gmail dot com @ 2006-03-03 14:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pato101 at gmail dot com  2006-03-03 14:26 -------
(In reply to comment #1)
> This is invalid C++.  Use -ffriend-injection to make it work.
> 
Wait, why is it invalid? At Bjarne Stroustrup's "C++ programming language"
third edition, chapter 11, section "11.5 Friends" at its end (page 279) says:
It is not unusual for all functions of one class to be friends of another.
There is a shorthand for this:
class List{
     friend class List_iterator;
     // ...
};

Note furthermore that the "a" class in my example is not causing any trouble
while the syntax is the same than for "c" execpt that it is already declared
above... Why would I use "friend class List_iterator" if "class List_iterator"
is declared above, and I can use just "friend List_iterator" instead?


-- 


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


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

* [Bug c++/26543] friend class declaration inside class scope ignored
  2006-03-03 10:03 [Bug c++/26543] New: friend class declaration inside class scope ignored pato101 at gmail dot com
                   ` (2 preceding siblings ...)
  2006-03-03 14:26 ` pato101 at gmail dot com
@ 2006-03-03 14:29 ` pinskia at gcc dot gnu dot org
  2006-03-03 14:39 ` pato101 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-03 14:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-03-03 14:29 -------
(In reply to comment #3)
> (In reply to comment #1)
> > This is invalid C++.  Use -ffriend-injection to make it work.
> > 
> Wait, why is it invalid?

This was valid pre-standard C++, ARM C++ but is no longer valid.  friends don't
inject at all.


-- 


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


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

* [Bug c++/26543] friend class declaration inside class scope ignored
  2006-03-03 10:03 [Bug c++/26543] New: friend class declaration inside class scope ignored pato101 at gmail dot com
                   ` (3 preceding siblings ...)
  2006-03-03 14:29 ` pinskia at gcc dot gnu dot org
@ 2006-03-03 14:39 ` pato101 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pato101 at gmail dot com @ 2006-03-03 14:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pato101 at gmail dot com  2006-03-03 14:39 -------
(In reply to comment #2)
> (In reply to comment #1)
> > Use -ffriend-injection to make it work.
> 
> Note -ffriend-injection will not work in this case as -ffriend-injection is
> only for friend functions and not for friend classes.
> Anyways this is all documented on the changes page for 4.0.
> http://gcc.gnu.org/gcc-4.0/changes.html
> 

OK, I'm not a C++ guru an I assume I'm wrong. Btw, I don't really understand
what injection is, and I've been unable to see what's wrong regarding what I
read at the gcc-4.0/changes.html page. I can live with that, for sure, so don't
worry; for me, knowing the fact is that kind of declaration is no longer valid
is enough.

You say that -ffriend-injection won't solve this issue. The problem is that
this syntax was common use before and I have tons of software with those
"artifacts"... is there any "compatibility option" to handle them?

Thanks for your attention.


-- 


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


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

end of thread, other threads:[~2006-03-03 14:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-03 10:03 [Bug c++/26543] New: friend class declaration inside class scope ignored pato101 at gmail dot com
2006-03-03 11:42 ` [Bug c++/26543] " rguenth at gcc dot gnu dot org
2006-03-03 13:44 ` pinskia at gcc dot gnu dot org
2006-03-03 14:26 ` pato101 at gmail dot com
2006-03-03 14:29 ` pinskia at gcc dot gnu dot org
2006-03-03 14:39 ` pato101 at gmail dot com

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).