Don't throw on non-structural type of expressions for can_substitute.

According to Jonathan/Barry, while template argument itself can't
have non-structural type, it could e.g. be implicitly convertible
to some non-structural type, so we shouldn't throw on non-structural
types in can_substitute.
This commit is contained in:
Jakub Jelinek
2025-10-18 20:48:39 +02:00
committed by Marek Polacek
parent edb051f3ba
commit 9dd2392b23
2 changed files with 2 additions and 7 deletions

View File

@@ -4448,11 +4448,6 @@ eval_can_substitute (location_t loc, const constexpr_ctx *ctx,
return throw_exception (loc, ctx,
N_("invalid argument to can_substitute"),
a, jump_target);
tree type = type_of (a, kind);
if (!structural_type_p (type))
return throw_exception (loc, ctx,
N_("argument without structural type"),
a, jump_target);
}
a = resolve_nondeduced_context (a, tf_warning_or_error);
TREE_VEC_ELT (rvec, i) = a;

View File

@@ -154,8 +154,7 @@ static_assert (could_substitute (^^S, { reflect_constant (42) }));
constexpr int n = 42;
static_assert (could_substitute (^^S, { ^^n }));
constexpr NS nsv (42);
// nsv doesn't have structural type
static_assert (!could_substitute (^^S, { ^^nsv }));
static_assert (could_substitute (^^S, { ^^nsv }));
static_assert (!can_substitute (^^S, {}));
static_assert (can_substitute (^^S, { ^^int }));
@@ -164,6 +163,7 @@ static_assert (can_substitute (^^S, { ^^NS }));
static_assert (!can_substitute (^^S, { ^^int, ^^long }));
static_assert (!can_substitute (^^S, { reflect_constant (42) }));
static_assert (!can_substitute (^^S, { ^^n }));
static_assert (!can_substitute (^^S, { ^^nsv }));
static_assert (!can_substitute (^^T, {}));
static_assert (!can_substitute (^^T, { ^^float, ^^int }));
constexpr float fv = 42.0f;