From 4d24a8896575dfb50d733d1213dbe00bb6df3ab3 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 1 Mar 2001 13:51:00 +0000 Subject: [PATCH] decl2.c (do_nonmember_using_decl): Don't complain if we find same function. cp: * decl2.c (do_nonmember_using_decl): Don't complain if we find same function. Do complain about ambiguating extern "C" declarations. testsuite: * g++.old-deja/g++.other/using9.C: New test. From-SVN: r40148 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/decl2.c | 25 +++++++++---------- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/g++.old-deja/g++.other/using9.C | 21 ++++++++++++++++ 4 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.other/using9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fc3fb94597b..c5d0c9516d9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2001-03-01 Nathan Sidwell + + * decl2.c (do_nonmember_using_decl): Don't complain if we find + same function. Do complain about ambiguating extern "C" + declarations. + 2001-02-28 Nathan Sidwell Remove floating point and complex type template constant parms. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index b371611e8ff..d115dccdeee 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5126,22 +5126,21 @@ do_nonmember_using_decl (scope, name, oldval, oldtype, newval, newtype) { 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 (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)))) { - 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); + /* 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; } - 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fd0371d944b..414c253c948 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-03-01 Nathan Sidwell + + * g++.old-deja/g++.other/using9.C: New test. + 2001-02-28 Ovidiu Predescu * objc/execute/bycopy-3.m: Added new test from Nicola Pero. diff --git a/gcc/testsuite/g++.old-deja/g++.other/using9.C b/gcc/testsuite/g++.old-deja/g++.other/using9.C new file mode 100644 index 00000000000..acfab509bab --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/using9.C @@ -0,0 +1,21 @@ +// Build don't link: +// +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Feb 2001 + +// 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 +} -- 2.30.2