On Tue, Nov 30, 2021 at 09:09:41PM -0500, Jason Merrill via Gcc-patches wrote: > For PR61825, honza changed tree_single_nonzero_warnv_p to prevent a later > declaration from marking a function as weak after we've determined that it > wasn't weak before. But we shouldn't do that for speculative folding; we > should only do it when we actually need a constant value. In C++, such a > context is called "manifestly constant-evaluated". In fold, this seems to > correspond to the folding_initializer flag, since in C this situation only > occurs in static initializers. > > This change makes nonzero-1.c well-formed; I've added a nonzero-1a.c to > verify that we delete the null check eventually if there is no weak > redeclaration. > > The varasm.c change is so that if we do get the weak redeclaration error, we > get it at the position of the weak declaration rather than the previous > declaration. > > Using the FOLD_INIT paths also affects floating point arithmetic: notably, > this makes floating point division by zero in a manifestly > constant-evaluated context constant, as in a C static initializer. I've had > some success convincing CWG that this is the right direction; C++ should > follow C's floating point semantics more than we have been doing, and Joseph > says that the C policy is that Annex F overrides other parts of the standard > that say that some operations are undefined. But since we're in stage 3, > I'm only making this change with the new flag -fconstexpr-fp-except. It may > turn on by default in a future release. > > I think this distinction is only relevant for binary operations; arithmetic > for the floating point case, comparison for possibly non-zero addresses. > > Tested x86_64-pc-linux-gnu, OK for trunk?
[...] > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt > index 4b8a094b206..5654f044ae4 100644 > --- a/gcc/c-family/c.opt > +++ b/gcc/c-family/c.opt > @@ -1615,6 +1615,10 @@ fconstexpr-cache-depth= > C++ ObjC++ Joined RejectNegative UInteger Var(constexpr_cache_depth) Init(8) > -fconstexpr-cache-depth=<number> Specify maximum constexpr recursion > cache depth. > > +fconstexpr-fp-except > +C++ ObjC++ Var(flag_constexpr_fp_except) Init(0) > +Allow IEC559 floating point exceptions in constant expressions Sorry about nitpicking but there's a missing period after 'expressions', which will break a test. Marek