This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libjava PATCH] Fix C++ friend function usage


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


Attachment: diff-java-ffriend-3
Description: application/java-vm


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]