On Fri, Nov 18, 2022 at 11:24:45AM -0500, Jason Merrill wrote:
> > Right, that's the C++17 implicit constexpr for lambdas, finish_function:
> >
> > /* Lambda closure members are implicitly constexpr if possible. */
> > if (cxx_dialect >= cxx17
> > && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
> > DECL_DECLARED_CONSTEXPR_P (fndecl)
> > = ((processing_template_decl
> > || is_valid_constexpr_fn (fndecl, /*complain*/false))
> > && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
>
> Yeah, I guess potential_constant_expression needs to be stricter in a
> lambda. Or perhaps any function that isn't already
> DECL_DECLARED_CONSTEXPR_P?
potential_constant_expression can't be relied on that it catches up
everything if it, even a simple if statement with a condition not yet
known to be 0 or non-0 results in just a requirement that at least
one of the substatements is potential constant, etc.
Similarly switch statements etc.
If there is a way to distinguish between functions with user
specified constexpr/consteval and DECL_DECLARED_CONSTEXPR_P set
through the above if condition, sure, cp_finish_decl ->
check_static_in_constexpr could be perhaps silent about those, but then
we want to diagnose it during constexpr evaluation at least. But in that
case having it a pedwarn rather than "this is a constant expression"
vs. "this is not a constant expression, if !ctx->quiet emit an error"
is something I don't see how to handle. Because something needs
to be returned, it is a constant expression or it is not.
Jakub