summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-04-11 13:06:05 -0400
committerJason Merrill <jason@redhat.com>2022-05-13 13:39:30 -0400
commit86d50501e487597d8b97f40d1c87dfcd694a9441 (patch)
tree0cc0956e630c1416937cc5f81f4acf90e297cd37
parent7b4bd8dbd8d07e298528b0f033102ce8f693e739 (diff)
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.
-rw-r--r--gcc/cp/call.c1
-rw-r--r--gcc/testsuite/g++.dg/lookup/new3.C10
2 files changed, 10 insertions, 1 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 65fbff3b893..53ca229b909 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4584,7 +4584,6 @@ build_operator_new_call (tree fnname, vec<tree, va_gc> **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 <new>
+struct Incomplete;
+template<class T> struct Holder { T t; };
+Holder<Incomplete> *p;
+void test() {
+ ::new (p) int;
+ new (p) int;
+}