This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
patch to decl_function_context
- To: gcc-patches at gcc dot gnu dot org
- Subject: patch to decl_function_context
- From: Jason Merrill <jason at cygnus dot com>
- Date: Wed, 15 Dec 1999 01:34:11 -0800
C++ virtual functions use DECL_CONTEXT for the class of the vtable
where we look up the function at runtime; this screws up
decl_function_context if the class in question doesn't happen to be at
the same scope as the class where the function is defined. However,
such functions always take a first argument of type 'pointer to real
context', so we can get the class we want from there.
C++ should really be fixed to use DECL_CONTEXT for the real context,
and use something else for the "virtual context". But we've been
saying that since before I started working on g++, and this workaround
is clean enough.
1999-12-15 Jason Merrill <jason@casey.cygnus.com>
* tree.c (decl_function_context): Handle virtual functions.
Index: tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.c,v
retrieving revision 1.107
diff -c -p -r1.107 tree.c
*** tree.c 1999/12/09 18:59:30 1.107
--- tree.c 1999/12/15 09:31:47
*************** decl_function_context (decl)
*** 4802,4807 ****
--- 4802,4816 ----
if (TREE_CODE (decl) == SAVE_EXPR)
context = SAVE_EXPR_CONTEXT (decl);
+ /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
+ where we look up the function at runtime. Such functions always take
+ a first argument of type 'pointer to real context'.
+
+ C++ should really be fixed to use DECL_CONTEXT for the real context,
+ and use something else for the "virtual context". */
+ else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
+ context = TYPE_MAIN_VARIANT
+ (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
else
context = DECL_CONTEXT (decl);