return arg;
}
+/* We can't fully resolve ARG given as a non-type template argument to TYPE,
+ because one of them is dependent. But we need to represent the
+ conversion for the benefit of cp_tree_equal. */
+
+static tree
+maybe_convert_nontype_argument (tree type, tree arg)
+{
+ /* Auto parms get no conversion. */
+ if (type_uses_auto (type))
+ return arg;
+ /* We don't need or want to add this conversion now if we're going to use the
+ argument for deduction. */
+ if (value_dependent_expression_p (arg))
+ return arg;
+
+ type = cv_unqualified (type);
+ tree argtype = TREE_TYPE (arg);
+ if (same_type_p (type, argtype))
+ return arg;
+
+ arg = build1 (IMPLICIT_CONV_EXPR, type, arg);
+ IMPLICIT_CONV_EXPR_NONTYPE_ARG (arg) = true;
+ return arg;
+}
+
/* Convert the indicated template ARG as necessary to match the
indicated template PARM. Returns the converted ARG, or
error_mark_node if the conversion was unsuccessful. Error and
argument specification is valid. */
val = convert_nontype_argument (t, orig_arg, complain);
else
- val = canonicalize_expr_argument (orig_arg, complain);
+ {
+ val = canonicalize_expr_argument (orig_arg, complain);
+ val = maybe_convert_nontype_argument (t, val);
+ }
+
if (val == NULL_TREE)
val = error_mark_node;
{
tree type = tsubst (TREE_TYPE (t), args, complain, in_decl);
tree expr = RECUR (TREE_OPERAND (t, 0));
+ if (dependent_type_p (type) || type_dependent_expression_p (expr))
+ {
+ retval = copy_node (t);
+ TREE_TYPE (retval) = type;
+ TREE_OPERAND (retval, 0) = expr;
+ RETURN (retval);
+ }
+ if (IMPLICIT_CONV_EXPR_NONTYPE_ARG (t))
+ /* We'll pass this to convert_nontype_argument again, we don't need
+ to actually perform any conversion here. */
+ RETURN (expr);
int flags = LOOKUP_IMPLICIT;
if (IMPLICIT_CONV_EXPR_DIRECT_INIT (t))
flags = LOOKUP_NORMAL;
if (targ)
{
+ if ((strict & UNIFY_ALLOW_INTEGER)
+ && TREE_TYPE (targ) && TREE_TYPE (arg)
+ && CP_INTEGRAL_TYPE_P (TREE_TYPE (targ)))
+ /* We're deducing from an array bound, the type doesn't matter. */
+ arg = fold_convert (TREE_TYPE (targ), arg);
int x = !cp_tree_equal (targ, arg);
if (x)
unify_inconsistency (explain_p, parm, targ, arg);
if (dependent_type_p (TREE_VALUE (arg_type)))
return true;
if (cxx_dialect >= cxx17)
- {
- /* A value-dependent noexcept-specifier makes the type dependent. */
- tree spec = TYPE_RAISES_EXCEPTIONS (type);
- if (spec && TREE_PURPOSE (spec)
- && value_dependent_expression_p (TREE_PURPOSE (spec)))
- return true;
- }
+ /* A value-dependent noexcept-specifier makes the type dependent. */
+ if (tree spec = TYPE_RAISES_EXCEPTIONS (type))
+ if (tree noex = TREE_PURPOSE (spec))
+ /* Treat DEFERRED_NOEXCEPT as non-dependent, since it doesn't
+ affect overload resolution and treating it as dependent breaks
+ things. */
+ if (TREE_CODE (noex) != DEFERRED_NOEXCEPT
+ && value_dependent_expression_p (noex))
+ return true;
return false;
}
/* -- an array type constructed from any dependent type or whose
if (!processing_template_decl || expression == NULL_TREE)
return false;
- /* A name declared with a dependent type. */
- if (DECL_P (expression) && type_dependent_expression_p (expression))
+ /* A type-dependent expression is also value-dependent. */
+ if (type_dependent_expression_p (expression))
return true;
switch (TREE_CODE (expression))
&& (TREE_CODE (DECL_INITIAL (expression)) == TREE_LIST
/* cp_finish_decl doesn't fold reference initializers. */
|| TREE_CODE (TREE_TYPE (expression)) == REFERENCE_TYPE
- || type_dependent_expression_p (DECL_INITIAL (expression))
|| value_dependent_expression_p (DECL_INITIAL (expression))))
return true;
if (DECL_HAS_VALUE_EXPR_P (expression))
{
tree value_expr = DECL_VALUE_EXPR (expression);
- if (type_dependent_expression_p (value_expr))
+ if (value_dependent_expression_p (value_expr))
return true;
}
return false;
case CONST_CAST_EXPR:
case REINTERPRET_CAST_EXPR:
case CAST_EXPR:
+ case IMPLICIT_CONV_EXPR:
/* These expressions are value-dependent if the type to which
the cast occurs is dependent or the expression being casted
is value-dependent. */
}
case TEMPLATE_ID_EXPR:
- /* If a TEMPLATE_ID_EXPR involves a dependent name, it will be
- type-dependent. */
- return type_dependent_expression_p (expression)
- || variable_concept_p (TREE_OPERAND (expression, 0));
+ return variable_concept_p (TREE_OPERAND (expression, 0));
case CONSTRUCTOR:
{