https://gcc.gnu.org/g:716f4482c5617f0525a1853c447e525c3c1771ba

commit r16-6725-g716f4482c5617f0525a1853c447e525c3c1771ba
Author: Patrick Palka <[email protected]>
Date:   Mon Jan 12 11:21:14 2026 -0500

    c++: deferred noexcept parsing for friend tmpl spec [PR123189]
    
    Since we now defer noexcept parsing for templated friends, a couple of
    routines related to deferred parsing need to be updated to cope with friend
    template specializations -- their TI_TEMPLATE is a TREE_LIST rather than
    a TEMPLATE_DECL, and they don't introduce new template parameters.
    
            PR c++/123189
    
    gcc/cp/ChangeLog:
    
            * name-lookup.cc (binding_to_template_parms_of_scope_p):
            Gracefully handle TEMPLATE_INFO whose TI_TEMPLATE is a TREE_LIST.
            * pt.cc (maybe_begin_member_template_processing): For a friend
            template specialization consider its class context instead.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/noexcept92.C: New test.
    
    Reviewed-by: Jason Merrill <[email protected]>

Diff:
---
 gcc/cp/name-lookup.cc                   |  1 +
 gcc/cp/pt.cc                            |  4 ++--
 gcc/testsuite/g++.dg/cpp0x/noexcept92.C | 11 +++++++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 5d93c13265da..eb6a18a18ad5 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -8004,6 +8004,7 @@ binding_to_template_parms_of_scope_p (cxx_binding 
*binding,
   /* The template of the current scope, iff said scope is a primary
      template.  */
   tmpl = (tinfo
+         && TREE_CODE (TI_TEMPLATE (tinfo)) == TEMPLATE_DECL
          && PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo))
          ? TI_TEMPLATE (tinfo)
          : NULL_TREE);
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 759418c344ec..bc735cfcf602 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -546,9 +546,9 @@ maybe_begin_member_template_processing (tree decl)
   int levels = 0;
   bool nsdmi = TREE_CODE (decl) == FIELD_DECL;
 
-  if (nsdmi)
+  if (nsdmi || decl_specialization_friend_p (decl))
     {
-      tree ctx = DECL_CONTEXT (decl);
+      tree ctx = nsdmi ? DECL_CONTEXT (decl) : DECL_CHAIN (decl);
       decl = (CLASSTYPE_TEMPLATE_INFO (ctx)
              /* Disregard full specializations (c++/60999).  */
              && uses_template_parms (ctx)
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept92.C 
b/gcc/testsuite/g++.dg/cpp0x/noexcept92.C
new file mode 100644
index 000000000000..a3588582adae
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept92.C
@@ -0,0 +1,11 @@
+// PR c++/123189
+// { dg-do compile { target c++11 } }
+
+template<class T> void f() noexcept(noexcept(T()));
+
+template<class T>
+struct A {
+  friend void f<T>() noexcept(noexcept(T()));
+};
+
+template struct A<int>;

Reply via email to