public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: operator new lookup [PR98249]
@ 2022-04-11 21:31 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-04-11 21:31 UTC (permalink / raw)
  To: gcc-patches

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.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/98249

gcc/cp/ChangeLog:

	* call.cc (build_operator_new_call): Just look in ::.

gcc/testsuite/ChangeLog:

	* g++.dg/lookup/new3.C: New test.
---
 gcc/cp/call.cc                     |  3 +--
 gcc/testsuite/g++.dg/lookup/new3.C | 10 ++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/lookup/new3.C

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 73fede5a3df..3a8d7e4b131 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -4899,8 +4899,7 @@ build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
        up in the global scope.
 
      we disregard block-scope declarations of "operator new".  */
-  fns = lookup_name (fnname, LOOK_where::NAMESPACE);
-  fns = lookup_arg_dependent (fnname, fns, *args);
+  fns = lookup_qualified_name (global_namespace, fnname);
 
   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 <new>
+struct Incomplete;
+template<class T> struct Holder { T t; };
+Holder<Incomplete> *p;
+void test() {
+    ::new (p) int;
+    new (p) int;
+}

base-commit: b1124648ff8f655307f264d7b353fd68e3b03e9c
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-11 21:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-11 21:31 [pushed] c++: operator new lookup [PR98249] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).