[libjava PATCH] Fix C++ friend function usage

Kriang Lerdsuwanakij lerdsuwa@users.sourceforge.net
Tue Nov 16 16:26:00 GMT 2004


Hi

This is the continuation work of my earlier patch:

  http://gcc.gnu.org/ml/java-patches/2004-q4/msg00316.html

The previous one dealt with friend class declarations that will
no longer work when the friend behavior in the C++ frontend is 
tighten up for standard comformance.  This patch deals with
friend function declarations.  The revised version of my
C++ patch

  http://gcc.gnu.org/ml/gcc-patches/2004-10/msg02056.html

will end up changing both friend class and friend function
behavior.  So changes for friend function part is necessary
as well.


Here is a simplified example what this patch does:

  namespace N { class B; }
  class N::B {
    friend void f();
  };

Throughout libjava, it is assumed that the function 'f' above
refers to the function in the global namespace, but it should
belong to namespace N.  To correct this the declarations are
changed to the form:

  namespace N { class B; }
  void f(); // Declaration so that we can use qualified name
            // in the friend declaration.
  class N::B {
    friend void ::f();
  };

to force the behavior the same even after g++ is fixed.

Note that parenthesis may be needed around function name such as

    friend C (::f)();

when 'C' is a type (not necessary a class or namespace).  This is 
in accordance to the DR125:

  http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#125


Tested on i686-pc-linux-gnu with no regressions.  OK for the mainline?

--Kriang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: diff-java-ffriend-3
Type: application/x-java-vm
Size: 35161 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20041116/96e6c094/attachment.bin>


More information about the Java-patches mailing list