On Wed, Nov 16, 2022 at 08:20:34AM -0500, Jason Merrill wrote:
> > Ok. But there is another issue, the
> > https://eel.is/c++draft/expr.const#5.2
> > spot that P2647R1 is changing didn't exist in C++20, it was only added with
> > P2242R3. So, if one would treat P2647R1 as a DR for C++20, one has to come
> > up with
> > a different standard modification.
> > Probably change the last bullet of:
> > [dcl.constexpr]/3
> > its function-body shall not enclose
> >
> > a goto statement,
> > an identifier label,
> > a definition of a variable of non-literal type or of static or thread
> > storage duration.
> > to
> > a definition of a variable of non-literal type or of a non-constexpr
> > variable of static or thread storage duration.
> > or so.
>
> Indeed, though the hypothetical C++20 change could still use the "usable in
> constant expressions" phrase.
Yes.
Though, with -std=c++20 we are rejected already in start_decl's
if (current_function_decl && VAR_P (decl)
&& DECL_DECLARED_CONSTEXPR_P (current_function_decl)
&& cxx_dialect < cxx23)
{
bool ok = false;
if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
error_at (DECL_SOURCE_LOCATION (decl),
"%qD defined %<thread_local%> in %qs function only "
"available with %<-std=c++2b%> or %<-std=gnu++2b%>", decl,
DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
? "consteval" : "constexpr");
else if (TREE_STATIC (decl))
error_at (DECL_SOURCE_LOCATION (decl),
"%qD defined %<static%> in %qs function only available "
"with %<-std=c++2b%> or %<-std=gnu++2b%>", decl,
DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
? "consteval" : "constexpr");
else
ok = true;
if (!ok)
cp_function_chain->invalid_constexpr = true;
}
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?
Jakub