2: DECL_THIS_EXTERN (in VAR_DECL, FUNCTION_DECL or PARM_DECL)
DECL_IMPLICIT_TYPEDEF_P (in a TYPE_DECL)
DECL_CONSTRAINT_VAR_P (in a PARM_DECL)
- TEMPLATE_DECL_COMPLEX_ALIAS_P (in TEMPLATE_DECL)
DECL_INSTANTIATING_NSDMI_P (in a FIELD_DECL)
USING_DECL_UNRELATED_P (in USING_DECL)
3: DECL_IN_AGGR_P.
#define TYPE_DECL_ALIAS_P(NODE) \
DECL_LANG_FLAG_6 (TYPE_DECL_CHECK (NODE))
-/* Nonzero for TEMPLATE_DECL means that it is a 'complex' alias template. */
-#define TEMPLATE_DECL_COMPLEX_ALIAS_P(NODE) \
- DECL_LANG_FLAG_2 (TEMPLATE_DECL_CHECK (NODE))
-
/* Nonzero for a type which is an alias for another type; i.e, a type
which declaration was written 'using name-of-type =
another-type'. */
extern tree tsubst_template_args (tree, tree, tsubst_flags_t, tree);
extern tree tsubst_template_arg (tree, tree, tsubst_flags_t, tree);
extern tree tsubst_function_parms (tree, tree, tsubst_flags_t, tree);
-extern tree most_general_template (tree);
+extern tree most_general_template (const_tree);
extern tree get_mostly_instantiated_function_type (tree);
extern bool problematic_instantiation_changed (void);
extern void record_last_problematic_instantiation (void);
static tree listify_autos (tree, tree);
static tree tsubst_template_parm (tree, tree, tsubst_flags_t);
static tree instantiate_alias_template (tree, tree, tsubst_flags_t);
-static bool complex_alias_template_p (const_tree tmpl);
static tree get_underlying_template (tree);
static tree tsubst_attributes (tree, tree, tsubst_flags_t, tree);
static tree canonicalize_expr_argument (tree, tsubst_flags_t);
constr = build_constraints (constr, NULL_TREE);
set_constraints (decl, constr);
}
- if (complex_alias_template_p (tmpl))
- TEMPLATE_DECL_COMPLEX_ALIAS_P (tmpl) = true;
}
}
return NULL_TREE;
}
+/* A cache of the result of complex_alias_template_p. */
+
+static GTY((deletable)) hash_map<const_tree, tree> *complex_alias_tmpl_info;
+
/* Data structure for complex_alias_template_*. */
struct uses_all_template_parms_data
{
int level;
- bool *seen;
+ tree *seen;
};
/* walk_tree callback for complex_alias_template_p. */
{
tree idx = get_template_parm_index (t);
if (TEMPLATE_PARM_LEVEL (idx) == data.level)
- data.seen[TEMPLATE_PARM_IDX (idx)] = true;
+ data.seen[TEMPLATE_PARM_IDX (idx)] = boolean_true_node;
}
default:;
return t;
/* Consider the expanded packs to be used outside the expansion... */
- data.seen[idx] = true;
+ data.seen[idx] = boolean_true_node;
}
/* ...but don't walk into the pattern. Consider PR104008:
using that alias can be ill-formed when the expansion is not, as with
the void_t template.
- Returns 1 if always complex, 0 if not complex, -1 if complex iff any of the
- template arguments are empty packs. */
+ If this predicate returns true in the ordinary case, the out parameter
+ SEEN_OUT is set to a TREE_VEC containing boolean_true_node at element I if
+ the I'th template parameter of the alias template is used in the alias. */
static bool
-complex_alias_template_p (const_tree tmpl)
+complex_alias_template_p (const_tree tmpl, tree *seen_out)
{
+ tmpl = most_general_template (tmpl);
+ if (!PRIMARY_TEMPLATE_P (tmpl))
+ return false;
+
/* A renaming alias isn't complex. */
if (get_underlying_template (CONST_CAST_TREE (tmpl)) != tmpl)
return false;
if (get_constraints (tmpl))
return true;
+ if (!complex_alias_tmpl_info)
+ complex_alias_tmpl_info = hash_map<const_tree, tree>::create_ggc (13);
+
+ if (tree *slot = complex_alias_tmpl_info->get (tmpl))
+ {
+ tree result = *slot;
+ if (result == boolean_false_node)
+ return false;
+ if (result == boolean_true_node)
+ return true;
+ gcc_assert (TREE_CODE (result) == TREE_VEC);
+ if (seen_out)
+ *seen_out = result;
+ return true;
+ }
+
struct uses_all_template_parms_data data;
tree pat = DECL_ORIGINAL_TYPE (DECL_TEMPLATE_RESULT (tmpl));
tree parms = DECL_TEMPLATE_PARMS (tmpl);
data.level = TMPL_PARMS_DEPTH (parms);
int len = TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (parms));
- data.seen = XALLOCAVEC (bool, len);
+ tree seen = make_tree_vec (len);
+ data.seen = TREE_VEC_BEGIN (seen);
for (int i = 0; i < len; ++i)
- data.seen[i] = false;
+ data.seen[i] = boolean_false_node;
if (cp_walk_tree_without_duplicates (&pat, complex_alias_template_r, &data))
- return true;
- for (int i = 0; i < len; ++i)
- if (!data.seen[i])
+ {
+ complex_alias_tmpl_info->put (tmpl, boolean_true_node);
return true;
+ }
+
+ for (int i = 0; i < len; ++i)
+ if (data.seen[i] != boolean_true_node)
+ {
+ complex_alias_tmpl_info->put (tmpl, seen);
+ if (seen_out)
+ *seen_out = seen;
+ return true;
+ }
+
+ complex_alias_tmpl_info->put (tmpl, boolean_false_node);
return false;
}
-/* If T is a specialization of a complex alias template with dependent
- template-arguments, return it; otherwise return NULL_TREE. If T is a
- typedef to such a specialization, return the specialization. */
+/* If T is a specialization of a complex alias template with a dependent
+ argument for an unused template parameter, return it; otherwise return
+ NULL_TREE. If T is a typedef to such a specialization, return the
+ specialization. */
tree
dependent_alias_template_spec_p (const_tree t, bool transparent_typedefs)
return NULL_TREE;
gcc_assert (TYPE_P (t));
- if (!typedef_variant_p (t))
+ if (!processing_template_decl || !typedef_variant_p (t))
return NULL_TREE;
- tree tinfo = TYPE_ALIAS_TEMPLATE_INFO (t);
- if (tinfo
- && TEMPLATE_DECL_COMPLEX_ALIAS_P (TI_TEMPLATE (tinfo))
- && (any_dependent_template_arguments_p
- (INNERMOST_TEMPLATE_ARGS (TI_ARGS (tinfo)))))
- return CONST_CAST_TREE (t);
+ if (tree tinfo = TYPE_ALIAS_TEMPLATE_INFO (t))
+ {
+ tree seen = NULL_TREE;
+ if (complex_alias_template_p (TI_TEMPLATE (tinfo), &seen))
+ {
+ tree args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (tinfo));
+ if (!seen)
+ {
+ if (any_dependent_template_arguments_p (args))
+ return CONST_CAST_TREE (t);
+ }
+ else
+ {
+ gcc_assert (TREE_VEC_LENGTH (args) == TREE_VEC_LENGTH (seen));
+ for (int i = 0, len = TREE_VEC_LENGTH (args); i < len; ++i)
+ if (TREE_VEC_ELT (seen, i) != boolean_true_node
+ && dependent_template_arg_p (TREE_VEC_ELT (args, i)))
+ return CONST_CAST_TREE (t);
+ }
+
+ return NULL_TREE;
+ }
+ }
if (transparent_typedefs)
{
`template <class T> template <class U> S<T*>::f(U)'. */
tree
-most_general_template (tree decl)
+most_general_template (const_tree decl)
{
if (TREE_CODE (decl) != TEMPLATE_DECL)
{
decl = DECL_TI_TEMPLATE (decl);
}
- return decl;
+ return CONST_CAST_TREE (decl);
}
/* Return the most specialized of the template partial specializations