On 11/16/22 09:46, Jakub Jelinek wrote:
On Wed, Nov 16, 2022 at 09:33:27AM -0500, Jason Merrill wrote:
and at that point I fear decl_maybe_constant_var_p will not work
properly.  Shall this hunk be moved somewhere else (cp_finish_decl?)
where we can already call it, or do the above in start_decl for
cxx_dialect < cxx20 and add a cxx_dialect == cxx20 hunk in cp_finish_decl?

Hmm, I'd expect decl_maybe_constant_var_p to work fine at this point.

For static constexpr vars sure, but what about
static const where start_decl doesn't know the initializer?
Sure, decl_maybe_constant_var_p will not crash in that case, but
it will return true even if the static const var doesn't have
a constant initializer.  Sure, we'd catch that later on when actually
trying to constexpr evaluate the function and hitting there the
spots added for C++23 in potential_constant_expression*/cxx_eval_*,
but it would mean that we don't reject it when nothing calls the functions.

I meant something like:
constexpr int bar (int x) { if (x) throw 1; return 0; }
constexpr int foo () { static const int a = bar (1); return 0; }
with -std=c++20 IMHO shouldn't be accepted, while in C++23 it should.

I'd expect us to reject that in C++20 in potential_constant_expression, but it's a fair point; it is awkward that P2242 wasn't also accepted as a DR.

Moving the check from start_decl to cp_finish_decl makes sense to me.

Jason

Reply via email to