TREE_PURPOSE (p) = TMPL_ARG (args, level, index);
}
else
- TREE_PURPOSE (p) = TREE_VALUE (p);
+ TREE_PURPOSE (p) = template_parm_to_arg (p);
return parms;
}
/* Get the argument and overload used for the requirement
and adjust it if we're going to expand later. */
- tree arg = template_parm_to_arg (build_tree_list (NULL_TREE, decl));
+ tree arg = template_parm_to_arg (decl);
if (apply_to_each_p && declared_pack_p)
arg = PACK_EXPANSION_PATTERN (TREE_VEC_ELT (ARGUMENT_PACK_ARGS (arg), 0));
current_template_parms = TREE_CHAIN (current_template_parms);
}
-/* Takes a TREE_LIST representing a template parameter and convert it
- into an argument suitable to be passed to the type substitution
- functions. Note that If the TREE_LIST contains an error_mark
- node, the returned argument is error_mark_node. */
+/* Takes a TEMPLATE_PARM_P or DECL_TEMPLATE_PARM_P node or a TREE_LIST
+ thereof, and converts it into an argument suitable to be passed to
+ the type substitution functions. Note that if the TREE_LIST contains
+ an error_mark node, the returned argument is error_mark_node. */
tree
template_parm_to_arg (tree t)
{
+ if (!t)
+ return NULL_TREE;
- if (t == NULL_TREE
- || TREE_CODE (t) != TREE_LIST)
- return t;
+ if (TREE_CODE (t) == TREE_LIST)
+ t = TREE_VALUE (t);
- if (error_operand_p (TREE_VALUE (t)))
+ if (error_operand_p (t))
return error_mark_node;
- t = TREE_VALUE (t);
-
- if (TREE_CODE (t) == TYPE_DECL
- || TREE_CODE (t) == TEMPLATE_DECL)
+ if (DECL_P (t) && DECL_TEMPLATE_PARM_P (t))
{
- t = TREE_TYPE (t);
+ if (TREE_CODE (t) == TYPE_DECL
+ || TREE_CODE (t) == TEMPLATE_DECL)
+ t = TREE_TYPE (t);
+ else
+ t = DECL_INITIAL (t);
+ }
+
+ gcc_assert (TEMPLATE_PARM_P (t));
+ if (TREE_CODE (t) == TEMPLATE_TYPE_PARM
+ || TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
+ {
if (TEMPLATE_TYPE_PARAMETER_PACK (t))
{
/* Turn this argument into a TYPE_ARGUMENT_PACK
}
else
{
- t = DECL_INITIAL (t);
-
if (TEMPLATE_PARM_PARAMETER_PACK (t))
{
/* Turn this argument into a NONTYPE_ARGUMENT_PACK
if (level > ftpi->max_depth)
return 0;
+ if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM)
+ /* We want the underlying TEMPLATE_TEMPLATE_PARM, not the
+ BOUND_TEMPLATE_TEMPLATE_PARM itself. */
+ t = TREE_TYPE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t));
+
/* Arguments like const T yield parameters like const T. This means that
a template-id like X<T, const T> would yield two distinct parameters:
T and const T. Adjust types to their unqualified versions. */
if (tree constr = TEMPLATE_PARM_CONSTRAINTS (node))
{
tree id = unpack_concept_check (constr);
- TREE_VEC_ELT (TREE_OPERAND (id, 1), 0) = template_parm_to_arg (t);
+ TREE_VEC_ELT (TREE_OPERAND (id, 1), 0) = t;
tree fold = finish_left_unary_fold_expr (constr, TRUTH_ANDIF_EXPR);
TEMPLATE_PARM_CONSTRAINTS (node) = fold;
--- /dev/null
+// PR c++/96531
+// { dg-do compile { target c++20 } }
+
+template<typename T>
+concept is_bool = __is_same(bool, T);
+
+template <typename... Ts>
+concept C = requires {
+ requires (is_bool<Ts> || ...);
+};
+
+template <bool... Bs>
+concept D = requires {
+ requires (Bs || ...);
+};
+
+template <typename... Ts>
+requires C<Ts...>
+void bar() {}
+
+template <bool... Bs>
+requires D<Bs...>
+void baz() {}
+
+int main() {
+ bar<int, char, bool>();
+ baz<false, true, false>();
+}