obj_arg = TREE_OPERAND (addr, 0);
}
}
- call = cxx_constant_value (call, obj_arg);
+ call = cxx_constant_value_sfinae (call, obj_arg, complain);
if (obj_arg && !error_operand_p (call))
call = build2 (INIT_EXPR, void_type_node, obj_arg, call);
call = convert_from_reference (call);
/* As above, but respect SFINAE. */
tree
-cxx_constant_value_sfinae (tree t, tsubst_flags_t complain)
+cxx_constant_value_sfinae (tree t, tree decl, tsubst_flags_t complain)
{
bool sfinae = !(complain & tf_error);
- tree r = cxx_eval_outermost_constant_expr (t, sfinae, true, true);
+ tree r = cxx_eval_outermost_constant_expr (t, sfinae, true, true, false, decl);
if (sfinae && !TREE_CONSTANT (r))
r = error_mark_node;
return r;
extern bool require_rvalue_constant_expression (tree);
extern bool require_potential_rvalue_constant_expression (tree);
extern tree cxx_constant_value (tree, tree = NULL_TREE);
-extern tree cxx_constant_value_sfinae (tree, tsubst_flags_t);
+extern tree cxx_constant_value_sfinae (tree, tree, tsubst_flags_t);
extern void cxx_constant_dtor (tree, tree);
extern tree cxx_constant_init (tree, tree = NULL_TREE);
extern tree maybe_constant_value (tree, tree = NULL_TREE, bool = false);
&& !glvalue_p (elt)
&& !TREE_CONSTANT (elt))
{
- elt = cxx_constant_value_sfinae (elt, complain);
+ elt = cxx_constant_value_sfinae (elt, NULL_TREE, complain);
if (elt == error_mark_node)
return false;
}
}
else
{
- r += foo (8 * x); // { dg-error "is not a constant expression" }
+ r += foo (8 * x); // { dg-error "is not a constant expression" "" { xfail *-*-* } }
}
if ! consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
{
- r += foo (32 * x);// { dg-error "is not a constant expression" }
+ r += foo (32 * x);// { dg-error "is not a constant expression" "" { xfail *-*-* } }
}
if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
{
--- /dev/null
+// Test SFINAE for a non-constant consteval call.
+// { dg-do compile { target c++20 } }
+
+consteval int deref(const int* x) { return *x; }
+
+template<const int* P, int = deref(P)> // { dg-bogus "null pointer" }
+constexpr int f(int) { return 0; }
+
+template<const int* P>
+constexpr int f(...) { return 1; }
+
+static_assert(f<nullptr>(0) == 1);