diff mbox series

c++: Avoid confusing 'nested' name

Message ID fdf611ad-c9c5-4070-06b1-92c85a6d4c54@acm.org
State New
Headers show
Series c++: Avoid confusing 'nested' name | expand

Commit Message

Nathan Sidwell Sept. 16, 2020, 3:10 p.m. UTC
instantiate_body has a local var call 'nested',	which indicates	that
this instantiation was caused during the body of some function -- not
necessarily its	containing scope.  That's confusing, let's just	use
'current_function_decl' directly.  Then	we can also simplify the
push_to_top_level logic, which /does/ indicate whether this is an
actual nested function.	 (C++ does not have nested functions, but OMP
ODRs fall into that category.  A follow up patch will use that more
usual meaning of 'nested' wrt to functions.)

         gcc/cp/
         * pt.c (instantiate_body): Remove 'nested' var,	simplify
         push_to_top logic.

pushing to trunk
diff mbox series

Patch

diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c
index e8aa950b8fa..289452ab740 100644
--- i/gcc/cp/pt.c
+++ w/gcc/cp/pt.c
@@ -25458,17 +25458,15 @@  instantiate_body (tree pattern, tree args, tree d)
   tree td = pattern;
   tree code_pattern = DECL_TEMPLATE_RESULT (td);
 
-  tree fn_context = decl_function_context (d);
-  if (LAMBDA_FUNCTION_P (d))
-    /* tsubst_lambda_expr resolved any references to enclosing functions.  */
-    fn_context = NULL_TREE;
-  bool nested = current_function_decl != NULL_TREE;
-  bool push_to_top = !(nested && fn_context == current_function_decl);
-
   vec<tree> omp_privatization_save;
-  if (nested)
+  if (current_function_decl)
     save_omp_privatization_clauses (omp_privatization_save);
 
+  bool push_to_top
+    = !(current_function_decl
+	&& !LAMBDA_FUNCTION_P (d)
+	&& decl_function_context (d) == current_function_decl);
+
   if (push_to_top)
     push_to_top_level ();
   else
@@ -25595,7 +25593,7 @@  instantiate_body (tree pattern, tree args, tree d)
   else
     pop_function_context ();
 
-  if (nested)
+  if (current_function_decl)
     restore_omp_privatization_clauses (omp_privatization_save);
 }