This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
typedef-named class member functions can be public
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: 05 Jul 2002 03:39:27 -0300
- Subject: typedef-named class member functions can be public
- Organization: GCC Team, Red Hat
A class defined like this:
typedef class {...} foo;
has linkage, but its member functions don't have the public flag set,
even when they're defined outside the class body. The problem appears
to be that duplicate_decls() just copies TREE_PUBLIC (olddecl) to the
new decl, so the public flag set in new decl is lost. Oops.
This patch fixes the problem. I can't include the testcase I was
given because it's derived from a proprietary testsuite, so I'd
appreciate if someone would come up with a testcase based on my
description of the problem for the GCC testsuite. Thanks in advance.
This patch was tested on athlon-pc-linux-gnu-x-mn10300-elf. Ok to
install?
Index: gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* decl.c (duplicate_decls): Let the PUBLIC flag of a new
FUNCTION_DECL make it to the resulting decl.
(grokfndecl): Update comment.
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.916
diff -u -p -r1.916 decl.c
--- gcc/cp/decl.c 1 Jul 2002 23:07:12 -0000 1.916
+++ gcc/cp/decl.c 5 Jul 2002 06:21:24 -0000
@@ -3374,6 +3374,13 @@ duplicate_decls (newdecl, olddecl)
(newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
+ /* If the original declaration was introduced within the class
+ body in a class whose name is given by a typedef declaration
+ (typedef class { foo(); } foo;) we have to turn the old
+ declaration public, so that when we copy the public attribute
+ from olddecl to newdecl, we get the right value. */
+ TREE_PUBLIC (olddecl) |= TREE_PUBLIC (newdecl);
+
/* Optionally warn about more than one declaration for the same
name, but don't warn about a function declaration followed by a
definition. */
@@ -8923,9 +8930,10 @@ grokfndecl (ctype, type, declarator, ori
publicp = 1;
}
- /* Members of anonymous types and local classes have no linkage; make
- them internal. */
- /* FIXME what if it gets a name from typedef? */
+ /* Members of anonymous types and local classes have no linkage;
+ make them internal. If we get the name of the class from a
+ typedef, the decl will be adjusted in duplicate_decls, when the
+ method is defined. */
if (ctype && (TYPE_ANONYMOUS_P (ctype)
|| decl_function_context (TYPE_MAIN_DECL (ctype))))
publicp = 0;
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist Professional serial bug killer