From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 3C75E3850425; Thu, 12 May 2022 21:14:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C75E3850425 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10719] c++: operator new lookup [PR98249] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 846bff4d4659d9b2026da574194599f38a00cc79 X-Git-Newrev: 6c69f7c449cc1c0d48e13b8680023a59f541260e Message-Id: <20220512211442.3C75E3850425@sourceware.org> Date: Thu, 12 May 2022 21:14:42 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 May 2022 21:14:42 -0000 https://gcc.gnu.org/g:6c69f7c449cc1c0d48e13b8680023a59f541260e commit r10-10719-g6c69f7c449cc1c0d48e13b8680023a59f541260e Author: Jason Merrill Date: Mon Apr 11 13:06:05 2022 -0400 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. Diff: --- gcc/cp/call.c | 1 - gcc/testsuite/g++.dg/lookup/new3.C | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 29e4a52b6c4..49eb673ebcc 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 00000000000..36afb5b48e2 --- /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; +}