From 6c69f7c449cc1c0d48e13b8680023a59f541260e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 11 Apr 2022 13:06:05 -0400 Subject: [PATCH] c++: operator new lookup [PR98249] The standard says, as we quote in the comment just above, that if we don't find operator new in the allocated type, it should be looked up in the global scope. This is specifically ::, not just any namespace, and we already give an error for an operator new declared in any other namespace. PR c++/98249 gcc/cp/ChangeLog: * call.c (build_operator_new_call): Just look in ::. gcc/testsuite/ChangeLog: * g++.dg/lookup/new3.C: New test. --- gcc/cp/call.c | 1 - gcc/testsuite/g++.dg/lookup/new3.C | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/lookup/new3.C diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 29e4a52b6c45..49eb673ebccf 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4682,7 +4682,6 @@ build_operator_new_call (tree fnname, vec **args, we disregard block-scope declarations of "operator new". */ fns = lookup_name_real (fnname, 0, 1, /*block_p=*/false, 0, 0); - fns = lookup_arg_dependent (fnname, fns, *args); if (align_arg) { diff --git a/gcc/testsuite/g++.dg/lookup/new3.C b/gcc/testsuite/g++.dg/lookup/new3.C new file mode 100644 index 000000000000..36afb5b48e28 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/new3.C @@ -0,0 +1,10 @@ +// PR c++/98249 + +#include +struct Incomplete; +template struct Holder { T t; }; +Holder *p; +void test() { + ::new (p) int; + new (p) int; +} -- 2.47.2