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-11 17:30:45 -0400
commitd087b59527a658a4de13febbb593edbf03339e93 (patch)
treed504a13bebeb975d6b605d41a9978c88f5a15295
parentb1124648ff8f655307f264d7b353fd68e3b03e9c (diff)
downloadgcc-d087b59527a658a4de13febbb593edbf03339e93.zip
gcc-d087b59527a658a4de13febbb593edbf03339e93.tar.gz
gcc-d087b59527a658a4de13febbb593edbf03339e93.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.cc (build_operator_new_call): Just look in ::. gcc/testsuite/ChangeLog: * g++.dg/lookup/new3.C: New test.
-rw-r--r--gcc/cp/call.cc3
-rw-r--r--gcc/testsuite/g++.dg/lookup/new3.C10
2 files changed, 11 insertions, 2 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 73fede5..3a8d7e4 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 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;
+}