From 3e76c270e1ce22f58f1f3b67768e7f1fa2a12c22 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 28 Feb 2005 08:26:41 +0000 Subject: PR c++/18838 2005-01-30 Mark Mitchell PR c++/19367 * name-lookup.c (do_nonmember_using_decl): Avoid overloading builtin declarations. PR c++/18838 * g++.dg/lookup/builtin2.C: New test. 2005-01-30 Mark Mitchell PR c++/19367 * g++.dg/lookup/builtin1.C: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-3_4-rhl-branch@95657 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/name-lookup.c | 31 ++++++++++++++++--------------- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/g++.dg/lookup/builtin2.C | 25 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/builtin2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 547b561457d..9411ae3a962 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2005-02-09 Alexandre Oliva + + PR c++/18838 + 2005-01-30 Mark Mitchell + PR c++/19367 + * name-lookup.c (do_nonmember_using_decl): Avoid overloading + builtin declarations. + 2005-02-21 Alexandre Oliva PR c++/20028 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 80f4c2946c2..50313f857ed 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2177,6 +2177,15 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, oldval = NULL_TREE; } + /* It is impossible to overload a built-in function; any + explicit declaration eliminates the built-in declaration. + So, if OLDVAL is a built-in, then we can just pretend it + isn't there. */ + if (oldval + && TREE_CODE (oldval) == FUNCTION_DECL + && DECL_ANTICIPATED (oldval)) + oldval = NULL_TREE; + *newval = oldval; for (tmp = decls.value; tmp; tmp = OVL_NEXT (tmp)) { @@ -2200,27 +2209,19 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)), TYPE_ARG_TYPES (TREE_TYPE (old_fn)))) { + if (DECL_ANTICIPATED (old_fn)) + abort (); + /* 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)) - { - /* If the OLD_FN was a builtin, there is now a - real declaration. */ - if (DECL_ANTICIPATED (old_fn)) - DECL_ANTICIPATED (old_fn) = 0; + break; + else + { + error ("%D is already declared in this scope", name); break; } - else if (!DECL_ANTICIPATED (old_fn)) - { - /* If the OLD_FN was really declared, the - declarations don't match. */ - error ("`%D' is already declared in this scope", name); - break; - } - - /* If the OLD_FN was not really there, just ignore - it and keep going. */ } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 45b3ea5e359..353c94f2835 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2005-02-09 Alexandre Oliva + + PR c++/18838 + * g++.dg/lookup/builtin2.C: New test. + 2005-01-30 Mark Mitchell + PR c++/19367 + * g++.dg/lookup/builtin1.C: New test. + 2005-02-21 Alexandre Oliva PR c++/20028 diff --git a/gcc/testsuite/g++.dg/lookup/builtin2.C b/gcc/testsuite/g++.dg/lookup/builtin2.C new file mode 100644 index 00000000000..ca9517ddc3e --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/builtin2.C @@ -0,0 +1,25 @@ +// PR c++/18838 +// { dg-do compile } + +extern "C" { + extern double fabs (double __x) throw () __attribute__ ((__const__)); + + __inline double + fabs (double __x) throw () { return __builtin_fabs (__x); } +} + +double fail_me(double __x) { return fabs(__x); } + +namespace std +{ + using ::fabs; +} + +typedef double (*realfn) (double); + +using std::fabs; + +int main () +{ + realfn myfn = fabs; +} -- cgit v1.2.3