From: Giovanni Bajo Date: Mon, 5 Jul 2004 15:56:10 +0000 (+0000) Subject: re PR c++/2518 (user-declared operator new hides standard one) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=030bbecdbb3935ea4728da13d46dc0f0a9ebda4f;p=gcc.git re PR c++/2518 (user-declared operator new hides standard one) PR c++/2518 * call.c (build_operator_new_call): Look only at global scope. PR c++/2518 * g++.dg/lookup/new1.C: New test. From-SVN: r84119 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f611cb3fce5..a760aa96beb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2004-07-05 Giovanni Bajo + + PR c++/2518 + * call.c (build_operator_new_call): Look only at global scope. + 2004-07-05 Nathan Sidwell * call.c (enforce_access): Expect TREE_BINFO. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 82355c2941c..b6983868cae 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2812,7 +2812,10 @@ build_operator_new_call (tree fnname, tree args, tree *size, tree *cookie_size) if (args == error_mark_node) return args; + /* A global operator new must be looked up only at global scope. */ + push_to_top_level(); fns = lookup_function_nonclass (fnname, args); + pop_from_top_level(); /* Figure out what function is being called. */ cand = perform_overload_resolution (fns, args, &candidates, &any_viable_p); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3b0a5d1b2c9..e12cd88c26f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-07-05 Giovanni Bajo + + PR c++/2518 + * g++.dg/lookup/new1.C: New test. + 2004-07-05 Volker Reichelt PR c++/11406 diff --git a/gcc/testsuite/g++.dg/lookup/new1.C b/gcc/testsuite/g++.dg/lookup/new1.C new file mode 100644 index 00000000000..a28d3e8968d --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/new1.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// Origin: +// PR c++/2518: operator new must not be looked up in local scope + +int main() { + int i; + void* operator new(unsigned s, int* p); + int* e = new(&i) int; // { dg-error "no matching function" } + int* f = new int; + return 0; +} + +// { dg-excess-errors "operator new" "list of candidates" }