This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Using declarations should not conflict (PR/2294) - TAKE 2
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: <gcc-patches at gcc dot gnu dot org>
- Cc: "Jason Merrill" <jason at redhat dot com>,"Giovanni Bajo" <giovannibajo at libero dot it>
- Date: Fri, 21 Nov 2003 20:27:43 +0100
- Subject: [C++ PATCH] Using declarations should not conflict (PR/2294) - TAKE 2
Hello,
this is my second attempt at fixing PR/2294. The previous patch was reverted
because it was breaking libjava bootstrap. It turned out to be a very easy
issue, the code accessing _Jv_* functions in the C++ frontend was expecting the
global name to be bound to a FUNCTION_DECL, not an OVERLOAD. My patch now
creates OVERLOADs for all the declarations (of non builtins), hence the bug.
This patch was verified in the following ways:
- Bootstrapped (c,c++,java) on i686-pc-linux-gnu, and regtested with no new
regressions (by myself).
- Bootstrapped on sparc-sun-solaris2.9 (-m64, -m32) and regtested with no new
regression (-m32 only) (by Andrew Tobler).
- Bootstrapped powerpc-apple-darwin7.0.0 and regtested with no new regressions.
(by Andrew Tobler)
Many thanks to Andrew for the big help with testing. Everything looks good to
me, so I hope there is no breakage this time.
The original testcase is already committed in the testcase
(g++.dg/lookup/using9.C) and this patch of course fixes it. The reduced testcase
for the libjava regression also compiles correctly of course, but DejaGnu
refuses to eat it, I think I'm missing something. Any ideas? Do I need some
dg-options to "activate" extern "Java" and the such?
OK for mainline? Gaby, I will prepare the 3.3 backport as soon as possible.
2003-11-21 Giovanni Bajo <giovannibajo@libero.it>
PR c++/2294
* name-lookup.c (push_overloaded_decl): Always construct an
OVERLOAD unless the declaration is a built-in.
(set_namespace_binding): While binding OVERLOADs with only one
declaration, we still need to call supplement_binding.
* init.c (build_new_1): Deal with an OVERLOAD set when
looking up for _Jv_AllocObject.
* except.c (build_throw): Likewise for _Jv_Throw.
Index: name-lookup.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.16
diff -c -p -r1.16 name-lookup.c
*** name-lookup.c 14 Oct 2003 20:34:41 -0000 1.16
--- name-lookup.c 21 Nov 2003 19:00:00 -0000
*************** push_overloaded_decl (tree decl, int fla
*** 1994,2000 ****
}
}
! if (old || TREE_CODE (decl) == TEMPLATE_DECL)
{
if (old && TREE_CODE (old) != OVERLOAD)
new_binding = ovl_cons (decl, ovl_cons (old, NULL_TREE));
--- 1997,2003 ----
}
}
! if (!DECL_ARTIFICIAL (decl))
{
if (old && TREE_CODE (old) != OVERLOAD)
new_binding = ovl_cons (decl, ovl_cons (old, NULL_TREE));
*************** push_overloaded_decl (tree decl, int fla
*** 2004,2010 ****
OVL_USED (new_binding) = 1;
}
else
- /* NAME is not ambiguous. */
new_binding = decl;
if (doing_global)
--- 2007,2012 ----
*************** set_namespace_binding (tree name, tree s
*** 2862,2868 ****
if (scope == NULL_TREE)
scope = global_namespace;
b = binding_for_name (NAMESPACE_LEVEL (scope), name);
! if (!b->value || TREE_CODE (val) == OVERLOAD || val == error_mark_node)
b->value = val;
else
supplement_binding (b, val);
--- 2867,2877 ----
if (scope == NULL_TREE)
scope = global_namespace;
b = binding_for_name (NAMESPACE_LEVEL (scope), name);
! if (!b->value
! /* If OVL_CHAIN is NULL, it's the first FUNCTION_DECL for this name,
! and we still need to call supplement_binding. */
! || (TREE_CODE (val) == OVERLOAD && OVL_CHAIN (val))
! || val == error_mark_node)
b->value = val;
else
supplement_binding (b, val);
Index: init.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.345
diff -c -p -r1.345 init.c
*** init.c 7 Oct 2003 07:07:03 -0000 1.345
--- init.c 21 Nov 2003 19:00:14 -0000
*************** build_new_1 (tree exp)
*** 2005,2015 ****
tree class_size = size_in_bytes (true_type);
static const char alloc_name[] = "_Jv_AllocObject";
use_java_new = 1;
! alloc_decl = IDENTIFIER_GLOBAL_VALUE (get_identifier (alloc_name));
! if (alloc_decl == NULL_TREE)
fatal_error ("call to Java constructor with `%s' undefined",
alloc_name);
!
class_addr = build1 (ADDR_EXPR, jclass_node, class_decl);
alloc_call = (build_function_call
(alloc_decl,
--- 2005,2020 ----
tree class_size = size_in_bytes (true_type);
static const char alloc_name[] = "_Jv_AllocObject";
use_java_new = 1;
! if (!get_global_value_if_present (get_identifier (alloc_name),
! &alloc_decl))
fatal_error ("call to Java constructor with `%s' undefined",
alloc_name);
! if (is_overloaded_fn (alloc_decl))
! {
! if (really_overloaded_fn (alloc_decl))
! fatal_error ("`%s' should never be overloaded", alloc_name);
! alloc_decl = OVL_FUNCTION (alloc_decl);
! }
class_addr = build1 (ADDR_EXPR, jclass_node, class_decl);
alloc_call = (build_function_call
(alloc_decl,
Index: except.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/except.c,v
retrieving revision 1.160
diff -c -p -r1.160 except.c
*** except.c 29 Sep 2003 21:19:10 -0000 1.160
--- except.c 21 Nov 2003 19:00:18 -0000
*************** build_throw (tree exp)
*** 637,642 ****
--- 637,643 ----
if (exp && decl_is_java_type (TREE_TYPE (exp), 1))
{
+ static const char throw_name[] = "_Jv_Throw";
tree fn = get_identifier ("_Jv_Throw");
if (!get_global_value_if_present (fn, &fn))
{
*************** build_throw (tree exp)
*** 645,650 ****
--- 646,657 ----
tmp = build_function_type (ptr_type_node, tmp);
fn = push_throw_library_fn (fn, tmp);
}
+ else if (is_overloaded_fn (fn))
+ {
+ if (really_overloaded_fn (fn))
+ fatal_error ("`%s' should never be overloaded", throw_name);
+ fn = OVL_FUNCTION (fn);
+ }
exp = build_function_call (fn, tree_cons (NULL_TREE, exp, NULL_TREE));
}