{
/* Wrapper to make a C++20 template parameter object const. */
op = tsubst_copy (op, args, complain, in_decl);
- if (TREE_CODE (op) == TEMPLATE_PARM_INDEX)
+ if (!CP_TYPE_CONST_P (TREE_TYPE (op)))
{
+ /* The template argument is not const, presumably because
+ it is still dependent, and so not the const template parm
+ object. */
tree type = tsubst (TREE_TYPE (t), args, complain, in_decl);
- return build1 (code, type, op);
- }
- else
- {
- gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (op))
- || (TREE_CODE (op) == IMPLICIT_CONV_EXPR
- && IMPLICIT_CONV_EXPR_NONTYPE_ARG (op)));
- return op;
+ gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p
+ (type, TREE_TYPE (op)));
+ if (TREE_CODE (op) == CONSTRUCTOR
+ || TREE_CODE (op) == IMPLICIT_CONV_EXPR)
+ {
+ /* Don't add a wrapper to these. */
+ op = copy_node (op);
+ TREE_TYPE (op) = type;
+ }
+ else
+ /* Do add a wrapper otherwise (in particular, if op is
+ another TEMPLATE_PARM_INDEX). */
+ op = build1 (code, type, op);
}
+ return op;
}
/* force_paren_expr can also create a VIEW_CONVERT_EXPR. */
else if (code == VIEW_CONVERT_EXPR && REF_PARENTHESIZED_P (t))