]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: current inst name lookup within noexcept-spec [PR122668]
authorPatrick Palka <ppalka@redhat.com>
Wed, 19 Nov 2025 16:10:38 +0000 (11:10 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 19 Nov 2025 16:10:38 +0000 (11:10 -0500)
Since we don't implement deferred noexcept-spec parsing of a friend
declaration, the r15-2117 change diagnosing name lookup failure for the
current instantiation ahead of time needs to be suppressed in this case.

PR c++/122668
PR c++/114764

gcc/cp/ChangeLog:

* pt.cc (dependentish_scope_p): Return true for the current
instantiation from within an immediately parsed noexcept-spec.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/noexcept91.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/noexcept91.C [new file with mode: 0644]

index 3b581b3fd36939bec5049b12d8f2d0733e3ad1de..6dc3a4c32493da49a2ddcbfc07c43b7306031184 100644 (file)
@@ -29030,7 +29030,16 @@ dependent_scope_p (tree scope)
 bool
 dependentish_scope_p (tree scope)
 {
-  return dependent_scope_p (scope) || any_dependent_bases_p (scope);
+  return dependent_scope_p (scope) || any_dependent_bases_p (scope)
+    /* A noexcept-spec is a complete-class context, so this should never hold.
+       But since we don't implement deferred noexcept-spec parsing of a friend
+       declaration (PR114764) we compensate by treating the current
+       instantiation as dependent to avoid bogus name lookup failures in this
+       case (PR122668).  */
+    || (cp_noexcept_operand
+       && CLASS_TYPE_P (scope)
+       && TYPE_BEING_DEFINED (scope)
+       && dependent_type_p (scope));
 }
 
 /* T is a SCOPE_REF.  Return whether it represents a non-static member of
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept91.C b/gcc/testsuite/g++.dg/cpp0x/noexcept91.C
new file mode 100644 (file)
index 0000000..590dfa6
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/122668
+// { dg-do compile { target c++11 } }
+
+template<class T>
+struct A {
+  friend void f1(A& a) noexcept(noexcept(a.g(0))) { }
+  friend void f2(A& a) noexcept(noexcept(A::g(0))) { }
+  static void g(int) noexcept;
+};
+
+int main() {
+  A<int> a;
+  static_assert(noexcept(f1(a)), "");
+  static_assert(noexcept(f2(a)), "");
+}