This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix bug 75 (a regression)
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH] Fix bug 75 (a regression)
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Thu, 01 Mar 2001 14:00:06 +0000
- Organization: Codesourcery LLC
Hi,
I've installed the attached on both the mainline and 3.0 branch, which
fixes bug 75, we we'd give an error when accessing a function already
in the current namespace via a using decl - that's not introducing the
function. It also now gives an error when the return type of extern "C"
functions so introduced _don't_ match.
built & tested on i686-pc-linux-gnu, approved by Mark.
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-02-26 Nathan Sidwell <nathan@codesourcery.com>
* decl2.c (do_nonmember_using_decl): Don't complain if we find
same function. Do complain about ambiguating extern "C"
declarations.
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.443
diff -c -3 -p -r1.443 decl2.c
*** decl2.c 2001/02/19 21:47:08 1.443
--- decl2.c 2001/02/26 15:50:44
*************** do_nonmember_using_decl (scope, name, ol
*** 5126,5147 ****
{
tree old_fn = OVL_CURRENT (tmp1);
! if (!OVL_USED (tmp1)
! && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
! TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
{
! if (!(DECL_EXTERN_C_P (new_fn)
! && DECL_EXTERN_C_P (old_fn)))
! /* There was already a non-using declaration in
! this scope with the same parameter types. */
! cp_error ("`%D' is already declared in this scope",
! name);
break;
}
- else if (duplicate_decls (new_fn, old_fn))
- /* We're re-using something we already used
- before. We don't need to add it again. */
- break;
}
/* If we broke out of the loop, there's no reason to add
--- 5126,5146 ----
{
tree old_fn = OVL_CURRENT (tmp1);
! if (new_fn == old_fn)
! /* The function already exists in the current namespace. */
! break;
! else if (OVL_USED (tmp1))
! continue; /* this is a using decl */
! else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
! TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
{
! /* There was already a non-using declaration in
! this scope with the same parameter types. If both
! are the same extern "C" functions, that's ok. */
! if (!decls_match (new_fn, old_fn))
! cp_error ("`%D' is already declared in this scope", name);
break;
}
}
/* If we broke out of the loop, there's no reason to add
// Build don't link:
//
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 Feb 2001 <nathan@codesourcery.com>
// Bug 75. using declarations cannot introduce functions which ambiguate
// those in the current namespace, BUT here we're reaccessing the current
// namespace -- the function is not being 'introduced'.
extern int a();
struct x {};
using ::x;
using ::a;
extern "C" void foo ();
namespace {
extern "C" int foo ();
using ::foo; // ERROR - already in use
}