https://gcc.gnu.org/g:e907bc4955ca7305fed4befff4c3d5f71d29d5e8

commit r17-3996-ge907bc4955ca7305fed4befff4c3d5f71d29d5e8
Author: Jason Merrill <[email protected]>
Date:   Mon Sep 7 23:55:11 2026 -0400

    c++: more maybe_push_to_top_level
    
    While looking at the PR127132 patch, I noticed that this seems like another
    place for maybe_push_to_top_level.  The lambda handling removed here (from
    PR58761) is very different from that in maybe_push_to_top_level, but
    lambda-nsdmi6.C still passes.
    
    gcc/cp/ChangeLog:
    
            * pt.cc (instantiate_class_template): Use maybe_push_to_top_level.

Diff:
---
 gcc/cp/pt.cc | 30 ++----------------------------
 1 file changed, 2 insertions(+), 28 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 28845214eedd..2fc0e06380df 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -12900,7 +12900,6 @@ instantiate_class_template (tree type)
   tree pbinfo;
   tree base_list;
   unsigned int saved_maximum_field_alignment;
-  tree fn_context;
 
   if (type == error_mark_node)
     return error_mark_node;
@@ -12961,22 +12960,7 @@ instantiate_class_template (tree type)
 
   maybe_diagnose_erroneous_template (t ? TI_TEMPLATE (t) : templ);
 
-  int saved_unevaluated_operand = cp_unevaluated_operand;
-  int saved_unevaluated_typeid_cutoff = cp_unevaluated_typeid_cutoff;
-  int saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
-
-  fn_context = decl_function_context (TYPE_MAIN_DECL (type));
-  /* Also avoid push_to_top_level for a lambda in an NSDMI.  */
-  if (!fn_context && LAMBDA_TYPE_P (type) && TYPE_CLASS_SCOPE_P (type))
-    fn_context = error_mark_node;
-  if (!fn_context)
-    push_to_top_level ();
-  else
-    {
-      cp_unevaluated_operand = 0;
-      cp_unevaluated_typeid_cutoff = 0;
-      c_inhibit_evaluation_warnings = 0;
-    }
+  bool push_to_top = maybe_push_to_top_level (TYPE_MAIN_DECL (type));
 
   mark_template_arguments_used (templ, CLASSTYPE_TI_ARGS (type));
 
@@ -13387,15 +13371,6 @@ instantiate_class_template (tree type)
        }
     }
 
-  if (fn_context)
-    {
-      /* Restore these before substituting into the lambda capture
-        initializers.  */
-      cp_unevaluated_operand = saved_unevaluated_operand;
-      cp_unevaluated_typeid_cutoff = saved_unevaluated_typeid_cutoff;
-      c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings;
-    }
-
   /* Set the file and line number information to whatever is given for
      the class itself.  This puts error messages involving generated
      implicit functions at a predictable point, and the same point
@@ -13435,8 +13410,7 @@ instantiate_class_template (tree type)
   popclass ();
   pop_scope (pushed_scope);
   maximum_field_alignment = saved_maximum_field_alignment;
-  if (!fn_context)
-    pop_from_top_level ();
+  maybe_pop_from_top_level (push_to_top);
   pop_tinst_level ();
 
   /* The vtable for a template class can be emitted in any translation

Reply via email to