re PR c++/2518 (user-declared operator new hides standard one)
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>
Mon, 5 Jul 2004 15:56:10 +0000 (15:56 +0000)
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>
Mon, 5 Jul 2004 15:56:10 +0000 (15:56 +0000)
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

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/new1.C [new file with mode: 0644]

index f611cb3fce5aa1ff805e002a7a64394dcdbc25c4..a760aa96beb6eb737fcf004aa99ebc36f7a35b91 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-05  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/2518
+       * call.c (build_operator_new_call): Look only at global scope.
+
 2004-07-05  Nathan Sidwell  <nathan@codesourcery.com>
 
        * call.c (enforce_access): Expect TREE_BINFO.
index 82355c2941c5928895bb52e24420669b83c7ab4d..b6983868caec2641b7d572969e449f04aacd810f 100644 (file)
@@ -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);
index 3b0a5d1b2c953e1c44f7914a5580ea84724642b4..e12cd88c26facdb00f513dbe4b2a5ebb58859226 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-05  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/2518
+       * g++.dg/lookup/new1.C: New test.
+
 2004-07-05  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        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 (file)
index 0000000..a28d3e8
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// Origin: <igodard at rational dot com>
+// 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" }