public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17210] New: Erroneous behaviour of friend declaration
@ 2004-08-27  8:35 victor dot judin at materna dot de
  2004-08-27  8:42 ` [Bug c++/17210] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: victor dot judin at materna dot de @ 2004-08-27  8:35 UTC (permalink / raw)
  To: gcc-bugs

During the compilation of the following source
1  class A{
     2  private:
     3          int F();
     4  public:
     5          A();
     6          ~A();
     7  };
     8
     9  class B{
    10  friend int A::F();
    11  //friend class A;
    12          int f( int );
    13  public:
    14          B();
    15          ~B();
    16          void Foo( int );
    17  };
    18
    19  int A::F()
    20  {
    21          B b;
    22          return  b.f( 1 );
    23  }
 comes the following error( "Fehler" means an error in German ):
bash-2.05$ g++ -c A.cpp
A.cpp:3: Fehler: `int A::F()' is private
A.cpp:10: Fehler: within this context

However, if the whole class A has been declared as a friend, i.e. 

 10  //friend int A::F();
 11  friend class A;

the compiler accepts it - the private member A::F works as a friend of B. As to
my knowledege, the access of friends is not of any importance - here's an
example from the Stroutsrup's "The C++ Programming Language ", 5.4.1:
1 class x {
2  // ...
3  void f();
4 };
5
6 class y {
7 // 
8 friend void x::f();
9 };
As you see, in this sample there is no mention at all whether the X::f() is
private, public or protected. Also the ISO/IEC C++ does not mention( at least
explicitly ) any restrictions. The code above works with GCC3.3.1, but not with
3.4.1. It is completely illogical to forbid the private member to be DECLARED as
a friend, but to allow the same function to ACT as a friend if the whole class
is friend-declared.
Here is again the gcc output:
bash-2.05$ gcc -v -save-temps -c A.cpp
Lese Spezifikationen von /opt/sfw/gcc-3.4/lib/gcc/sparc-sun-solaris2.9/3.4.1/specs
Konfiguriert mit: ../gcc-3.4.1/configure --enable-shared --enable-threads
--prefix=/opt/sfw/gcc-3.4
Thread-Modell: posix
gcc-Version 3.4.1
 /opt/sfw/gcc-3.4/libexec/gcc/sparc-sun-solaris2.9/3.4.1/cc1plus -E -quiet -v
A.cpp -mcpu=v7 -o A.ii
nicht vorhandenes Verzeichnis
»/opt/sfw/gcc-3.4/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../sparc-sun-solaris2.9/include«
wird ignoriert
#include "..." - Suche beginnt hier:
#include <...> - Suche beginnt hier:
 /opt/sfw/gcc-3.4/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1
 /opt/sfw/gcc-3.4/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/sparc-sun-solaris2.9
 /opt/sfw/gcc-3.4/lib/gcc/sparc-sun-solaris2.9/3.4.1/../../../../include/c++/3.4.1/backward
 /usr/local/include
 /opt/sfw/gcc-3.4/include
 /opt/sfw/gcc-3.4/lib/gcc/sparc-sun-solaris2.9/3.4.1/include
 /usr/include
Ende der Suchliste.
 /opt/sfw/gcc-3.4/libexec/gcc/sparc-sun-solaris2.9/3.4.1/cc1plus -fpreprocessed
A.ii -quiet -dumpbase A.cpp -mcpu=v7 -auxbase A -version -o A.s
GNU C++ version 3.4.1 (sparc-sun-solaris2.9)
        compiled by GNU C version 2.95.3.2 20010315 (release) (std::string patch).
GGC-Heuristik: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
A.cpp:3: Fehler: `int A::F()' is private
A.cpp:10: Fehler: within this context

-- 
           Summary: Erroneous behaviour of friend declaration
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: victor dot judin at materna dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.4.1
  GCC host triplet: SunOS XXXX 5.9 Generic_112233-11 sun4u sparc SUNW,Ultra-
                    80


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


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

end of thread, other threads:[~2004-08-27  8:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-27  8:35 [Bug c++/17210] New: Erroneous behaviour of friend declaration victor dot judin at materna dot de
2004-08-27  8:42 ` [Bug c++/17210] " pinskia at gcc dot gnu dot 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).