This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] [PR2518] Correct lookup of operator new


Hello,

despite being a very old bug, the fix for this looks trivial enough.
build_operator_new_call is meant to call a global operator new (as specified by
[expr.new]/9, and also documented at the top of the function), but we were
forgetting to push to the global scope while doing the lookup.

Fixed thus. Tested on i686-pc-linux-gnu with no new regressions, OK for
mainline?

Giovanni Bajo
[P.S: other unreviewed C++ patches of mine here:
http://gcc.gnu.org/ml/gcc-patches/2004-06/msg01897.html]


cp/
        * call.c (build_operator_new_call): Look only at global scope.

testsuite/
        * g++.dg/lookup/new1.C: New test.


Index: call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.485
diff -c -3 -p -r1.485 call.c
*** call.c 26 Jun 2004 21:11:17 -0000 1.485
--- call.c 29 Jun 2004 16:39:09 -0000
*************** build_operator_new_call (tree fnname, tr
*** 2809,2815 ****
--- 2809,2818 ----
    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);



// { 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" }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]