aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-04-11 13:06:05 -0400
committerJason Merrill <jason@redhat.com>2022-04-12 16:12:49 -0400
commit7aa5f05583066f5b3146c999319288631c75597f (patch)
treec07f789315d290b38ae870e04e2c4799733afbfa
parentc52cd0b35d356565f67f7956f4defc022dfa2172 (diff)
downloadgcc-7aa5f05583066f5b3146c999319288631c75597f.zip
gcc-7aa5f05583066f5b3146c999319288631c75597f.tar.gz
gcc-7aa5f05583066f5b3146c999319288631c75597f.tar.bz2
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 13cb308..55bb9c4 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4764,7 +4764,6 @@ build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
we disregard block-scope declarations of "operator new". */
fns = lookup_name (fnname, LOOK_where::NAMESPACE);
- 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 0000000..36afb5b
--- /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;
+}