c++: uses_template_parms cleanups
authorMarek Polacek <polacek@redhat.com>
Wed, 27 Apr 2022 22:36:29 +0000 (18:36 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 2 May 2022 16:25:24 +0000 (12:25 -0400)
gcc/cp/ChangeLog:

* cp-tree.h (uses_template_parms): Adjust declaration.
* pt.cc (uses_template_parms): Return bool.  Use a RAII sentinel.

gcc/cp/cp-tree.h
gcc/cp/pt.cc

index 7217799..6de29c0 100644 (file)
@@ -7312,7 +7312,7 @@ extern tree lookup_template_class         (tree, tree, tree, tree,
                                                 int, tsubst_flags_t);
 extern tree lookup_template_function           (tree, tree);
 extern tree lookup_template_variable           (tree, tree);
-extern int uses_template_parms                 (tree);
+extern bool uses_template_parms                        (tree);
 extern bool uses_template_parms_level          (tree, int);
 extern bool in_template_function               (void);
 extern bool need_generic_capture               (void);
index e600654..23fbd82 100644 (file)
@@ -10884,35 +10884,30 @@ find_template_parameters (tree t, tree ctx_parms)
 
 /* Returns true if T depends on any template parameter.  */
 
-int
+bool
 uses_template_parms (tree t)
 {
-  if (t == NULL_TREE)
+  if (t == NULL_TREE || t == error_mark_node)
     return false;
 
-  bool dependent_p;
-  int saved_processing_template_decl;
+  /* Namespaces can't depend on any template parameters.  */
+  if (TREE_CODE (t) == NAMESPACE_DECL)
+    return false;
+
+  processing_template_decl_sentinel ptds (/*reset*/false);
+  ++processing_template_decl;
 
-  saved_processing_template_decl = processing_template_decl;
-  if (!saved_processing_template_decl)
-    processing_template_decl = 1;
   if (TYPE_P (t))
-    dependent_p = dependent_type_p (t);
+    return dependent_type_p (t);
   else if (TREE_CODE (t) == TREE_VEC)
-    dependent_p = any_dependent_template_arguments_p (t);
+    return any_dependent_template_arguments_p (t);
   else if (TREE_CODE (t) == TREE_LIST)
-    dependent_p = (uses_template_parms (TREE_VALUE (t))
-                  || uses_template_parms (TREE_CHAIN (t)));
+    return (uses_template_parms (TREE_VALUE (t))
+           || uses_template_parms (TREE_CHAIN (t)));
   else if (TREE_CODE (t) == TYPE_DECL)
-    dependent_p = dependent_type_p (TREE_TYPE (t));
-  else if (t == error_mark_node || TREE_CODE (t) == NAMESPACE_DECL)
-    dependent_p = false;
+    return dependent_type_p (TREE_TYPE (t));
   else
-    dependent_p = instantiation_dependent_expression_p (t);
-
-  processing_template_decl = saved_processing_template_decl;
-
-  return dependent_p;
+    return instantiation_dependent_expression_p (t);
 }
 
 /* Returns true iff we're processing an incompletely instantiated function