public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
@ 2020-08-31  9:41 Laurent.Rineau__gcc at normalesup dot org
  2020-08-31  9:52 ` [Bug libstdc++/96862] " jakub at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Laurent.Rineau__gcc at normalesup dot org @ 2020-08-31  9:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

            Bug ID: 96862
           Summary: -frounding-math -std=c++2a error: '(1.29e+2 *
                    6.9314718055994529e-1)' is not a constant expression
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Laurent.Rineau__gcc at normalesup dot org
  Target Milestone: ---

Commit e6c76f0d3327bf00c96f5a63961c1d5ab77512db introduced a compilation error
with `-frounding-math -std=c++2a`: it seems that, with `-frounding-math` a
floating-point expression cannot be constexpr.


# cat test.cpp
#include <string>
# g++ --version
g++ (GCC) 11.0.0 20200828 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# g++ -std=c++2a -frounding-math test.cpp
In file included from /usr/local/include/c++/11.0.0/bits/range_access.h:40,
                 from /usr/local/include/c++/11.0.0/string:54,
                 from test.cpp:1:
/usr/local/include/c++/11.0.0/bits/max_size_type.h:708:35: error: '(1.29e+2 *
6.9314718055994529e-1)' is not a constant expression
  708 |         = static_cast<int>(digits * numbers::ln2 / numbers::ln10);
      |                            ~~~~~~~^~~~~~~~~~~~~~
/usr/local/include/c++/11.0.0/bits/max_size_type.h:734:50: error:
'(8.8722839111672997e+1 / 2.3025850929940459e+0)' is not a constant expression
  734 |         = static_cast<int>(digits * numbers::ln2 / numbers::ln10);
      |                            ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug libstdc++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
@ 2020-08-31  9:52 ` jakub at gcc dot gnu.org
  2020-08-31 10:57 ` redi at gcc dot gnu.org
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-31  9:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org,
                   |                            |redi at gcc dot gnu.org
   Target Milestone|---                         |11.0

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Using floating point arithmetics for
+      static constexpr int digits10                                            
+       = static_cast<int>(digits * numbers::ln2 / numbers::ln10);              
seems unsafe, indeed with -frounding-math it can't be evaluated at compile
time, as it depends on the rounding mode.
Perhaps add a simple constexpr function that will compute this iteratively?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug libstdc++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
  2020-08-31  9:52 ` [Bug libstdc++/96862] " jakub at gcc dot gnu.org
@ 2020-08-31 10:57 ` redi at gcc dot gnu.org
  2020-08-31 11:12 ` jakub at gcc dot gnu.org
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-31 10:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think this is a compiler bug. The arithmetic must be valid in constexpr. It
does not have to give the same result as it would during runtime evaluation, so
I think constexpr evaluation should not be disabled by -frounding-math.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug libstdc++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
  2020-08-31  9:52 ` [Bug libstdc++/96862] " jakub at gcc dot gnu.org
  2020-08-31 10:57 ` redi at gcc dot gnu.org
@ 2020-08-31 11:12 ` jakub at gcc dot gnu.org
  2020-08-31 13:06 ` [Bug c++/96862] " rguenth at gcc dot gnu.org
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-31 11:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What fold-const.c has is:
      /* Don't constant fold this floating point operation if the
         result may dependent upon the run-time rounding mode and
         flag_rounding_math is set, or if GCC's software emulation
         is unable to accurately represent the result.  */
      if ((flag_rounding_math
           || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
          && (inexact || !real_identical (&result, &value)))
        return NULL_TREE;
i.e. if the result is inexact, it punts with -frounding-math (or for IBM double
double without -ffast-math).
So are you suggesting that constexpr.c should temporarily disable
flag_rounding_math during !allow_non_constant mode (or rather
manifestly_const_eval || !allow_non_constant mode), perhaps directly in
cxx_eval_outermost_constant_expr, on the basis that constant evaluation happens
when the rounding mode couldn't be changed?
For constant evaluation not required by the standard we need to still punt
IMNSHO, as that is normally evaluated at runtime where it could be affected by
rounding mode.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (2 preceding siblings ...)
  2020-08-31 11:12 ` jakub at gcc dot gnu.org
@ 2020-08-31 13:06 ` rguenth at gcc dot gnu.org
  2020-08-31 13:17 ` Laurent.Rineau__gcc at normalesup dot org
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-31 13:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.0                        |---
          Component|libstdc++                   |c++
           Keywords|                            |rejects-valid
            Version|unknown                     |11.0

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (3 preceding siblings ...)
  2020-08-31 13:06 ` [Bug c++/96862] " rguenth at gcc dot gnu.org
@ 2020-08-31 13:17 ` Laurent.Rineau__gcc at normalesup dot org
  2020-08-31 13:40 ` glisse at gcc dot gnu.org
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Laurent.Rineau__gcc at normalesup dot org @ 2020-08-31 13:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #4 from Laurent Rineau <Laurent.Rineau__gcc at normalesup dot org> ---
At the compiler level, I do not think the bug is related to `-std=c++2a`. That
flags was there only to trigger the bug from the recent versions of libstdc++
since:

commit e6c76f0d3327bf00c96f5a63961c1d5ab77512db
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 19 09:12:55 2020 -0400

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (4 preceding siblings ...)
  2020-08-31 13:17 ` Laurent.Rineau__gcc at normalesup dot org
@ 2020-08-31 13:40 ` glisse at gcc dot gnu.org
  2020-08-31 13:57 ` redi at gcc dot gnu.org
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-08-31 13:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #5 from Marc Glisse <glisse at gcc dot gnu.org> ---
"[Note: This document does not require an implementation to support the 
FENV_ACCESS pragma; it is implementation-defined (15.8) whether the pragma 
is supported. As a consequence, it is implementation-defined whether 
these functions can be used to test floating-point status flags, set 
floating-point control modes, or run under non-default mode settings. If 
the pragma is used to enable control over the floating-point environment, 
this document does not specify the effect on floating-point evaluation in 
constant expressions. — end note]"

So the C++ standard lets us choose what we want gcc to do in this case. The C
standard is of course more precise, but using its own definition of constant
expressions

http://port70.net/~nsz/c/c11/n1570.html#F.8.4
"1 An arithmetic constant expression of floating type, other than one in an
initializer for an object that has static or thread storage duration, is
evaluated (as if) during execution; thus, it is affected by any operative
floating-point control modes and raises floating-point exceptions as required
by IEC 60559 (provided the state for the FENV_ACCESS pragma is ''on'').366)

2 EXAMPLE

          #include <fenv.h>
          #pragma STDC FENV_ACCESS ON
          void f(void)
          {
                float w[] = { 0.0/0.0 };                  //   raises an
exception
                static float x = 0.0/0.0;                 //   does not raise
an exception
                float y = 0.0/0.0;                        //   raises an
exception
                double z = 0.0/0.0;                       //   raises an
exception
                /* ... */
          }

3 For the static initialization, the division is done at translation time,
raising no (execution-time) floating- point exceptions. On the other hand, for
the three automatic initializations the invalid division occurs at execution
time."

So Jakub's proposition makes sense, fold inexact operations when we have to
(and use default (nearest) rounding in that case, as long as we don't have
pragma fenv_round). Initializing a global (before main starts) also looks like
a place where folding could make sense, although it is less important.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (5 preceding siblings ...)
  2020-08-31 13:40 ` glisse at gcc dot gnu.org
@ 2020-08-31 13:57 ` redi at gcc dot gnu.org
  2020-08-31 14:06 ` jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-31 13:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also C++ [expr.const] p12.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (6 preceding siblings ...)
  2020-08-31 13:57 ` redi at gcc dot gnu.org
@ 2020-08-31 14:06 ` jakub at gcc dot gnu.org
  2020-08-31 14:22 ` glisse at gcc dot gnu.org
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-31 14:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49160
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49160&action=edit
gcc11-pr96862.patch

Untested patch.  e and f initializers are still evaluated at runtime and will
depend on the rounding mode.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (7 preceding siblings ...)
  2020-08-31 14:06 ` jakub at gcc dot gnu.org
@ 2020-08-31 14:22 ` glisse at gcc dot gnu.org
  2020-08-31 14:29 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-08-31 14:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #8 from Marc Glisse <glisse at gcc dot gnu.org> ---
Should we handle flag_trapping_math at the same time?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (8 preceding siblings ...)
  2020-08-31 14:22 ` glisse at gcc dot gnu.org
@ 2020-08-31 14:29 ` jakub at gcc dot gnu.org
  2020-09-03 18:12 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-31 14:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I don't know.
fold-const.c has:
#define START_FOLD_INIT \
  int saved_signaling_nans = flag_signaling_nans;\
  int saved_trapping_math = flag_trapping_math;\
  int saved_rounding_math = flag_rounding_math;\
  int saved_trapv = flag_trapv;\
  int saved_folding_initializer = folding_initializer;\
  flag_signaling_nans = 0;\
  flag_trapping_math = 0;\
  flag_rounding_math = 0;\
  flag_trapv = 0;\
  folding_initializer = 1;

#define END_FOLD_INIT \
  flag_signaling_nans = saved_signaling_nans;\
  flag_trapping_math = saved_trapping_math;\
  flag_rounding_math = saved_rounding_math;\
  flag_trapv = saved_trapv;\
  folding_initializer = saved_folding_initializer;

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (9 preceding siblings ...)
  2020-08-31 14:29 ` jakub at gcc dot gnu.org
@ 2020-09-03 18:12 ` cvs-commit at gcc dot gnu.org
  2020-09-11  7:47 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-03 18:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:6641d6d3fe79113f8d9f3ced355aea79bffda822

commit r11-2998-g6641d6d3fe79113f8d9f3ced355aea79bffda822
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Sep 3 20:11:43 2020 +0200

    c++: Disable -frounding-math during manifestly constant evaluation
[PR96862]

    As discussed in the PR, fold-const.c punts on floating point constant
    evaluation if the result is inexact and -frounding-math is turned on.
          /* Don't constant fold this floating point operation if the
             result may dependent upon the run-time rounding mode and
             flag_rounding_math is set, or if GCC's software emulation
             is unable to accurately represent the result.  */
          if ((flag_rounding_math
               || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
              && (inexact || !real_identical (&result, &value)))
            return NULL_TREE;
    Jonathan said that we should be evaluating them anyway, e.g. conceptually
    as if they are done with the default rounding mode before user had a chance
    to change that, and e.g. in C in initializers it is also ignored.
    In fact, fold-const.c for C initializers turns off various other options:

    /* Perform constant folding and related simplification of initializer
       expression EXPR.  These behave identically to "fold_buildN" but ignore
       potential run-time traps and exceptions that fold must preserve.  */

      int saved_signaling_nans = flag_signaling_nans;\
      int saved_trapping_math = flag_trapping_math;\
      int saved_rounding_math = flag_rounding_math;\
      int saved_trapv = flag_trapv;\
      int saved_folding_initializer = folding_initializer;\
      flag_signaling_nans = 0;\
      flag_trapping_math = 0;\
      flag_rounding_math = 0;\
      flag_trapv = 0;\
      folding_initializer = 1;

      flag_signaling_nans = saved_signaling_nans;\
      flag_trapping_math = saved_trapping_math;\
      flag_rounding_math = saved_rounding_math;\
      flag_trapv = saved_trapv;\
      folding_initializer = saved_folding_initializer;

    So, shall cxx_eval_outermost_constant_expr instead turn off all those
    options (then warning_sentinel wouldn't be the right thing to use, but
given
    the 8 or how many return stmts in cxx_eval_outermost_constant_expr, we'd
    need a RAII class for this.  Not sure about the folding_initializer, that
    one is affecting complex multiplication and division constant evaluation
    somehow.

    2020-09-03  Jakub Jelinek  <jakub@redhat.com>

            PR c++/96862
            * constexpr.c (cxx_eval_outermost_constant_expr): Temporarily
disable
            flag_rounding_math during manifestly constant evaluation.

            * g++.dg/cpp1z/constexpr-96862.C: New test.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (10 preceding siblings ...)
  2020-09-03 18:12 ` cvs-commit at gcc dot gnu.org
@ 2020-09-11  7:47 ` cvs-commit at gcc dot gnu.org
  2020-09-16 19:23 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-11  7:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:38a13f9f70c2a60d831dd03a9bfc2e58bd80d888

commit r10-8731-g38a13f9f70c2a60d831dd03a9bfc2e58bd80d888
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Sep 3 20:11:43 2020 +0200

    c++: Disable -frounding-math during manifestly constant evaluation
[PR96862]

    As discussed in the PR, fold-const.c punts on floating point constant
    evaluation if the result is inexact and -frounding-math is turned on.
          /* Don't constant fold this floating point operation if the
             result may dependent upon the run-time rounding mode and
             flag_rounding_math is set, or if GCC's software emulation
             is unable to accurately represent the result.  */
          if ((flag_rounding_math
               || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
              && (inexact || !real_identical (&result, &value)))
            return NULL_TREE;
    Jonathan said that we should be evaluating them anyway, e.g. conceptually
    as if they are done with the default rounding mode before user had a chance
    to change that, and e.g. in C in initializers it is also ignored.
    In fact, fold-const.c for C initializers turns off various other options:

    /* Perform constant folding and related simplification of initializer
       expression EXPR.  These behave identically to "fold_buildN" but ignore
       potential run-time traps and exceptions that fold must preserve.  */

      int saved_signaling_nans = flag_signaling_nans;\
      int saved_trapping_math = flag_trapping_math;\
      int saved_rounding_math = flag_rounding_math;\
      int saved_trapv = flag_trapv;\
      int saved_folding_initializer = folding_initializer;\
      flag_signaling_nans = 0;\
      flag_trapping_math = 0;\
      flag_rounding_math = 0;\
      flag_trapv = 0;\
      folding_initializer = 1;

      flag_signaling_nans = saved_signaling_nans;\
      flag_trapping_math = saved_trapping_math;\
      flag_rounding_math = saved_rounding_math;\
      flag_trapv = saved_trapv;\
      folding_initializer = saved_folding_initializer;

    So, shall cxx_eval_outermost_constant_expr instead turn off all those
    options (then warning_sentinel wouldn't be the right thing to use, but
given
    the 8 or how many return stmts in cxx_eval_outermost_constant_expr, we'd
    need a RAII class for this.  Not sure about the folding_initializer, that
    one is affecting complex multiplication and division constant evaluation
    somehow.

    2020-09-03  Jakub Jelinek  <jakub@redhat.com>

            PR c++/96862
            * constexpr.c (cxx_eval_outermost_constant_expr): Temporarily
disable
            flag_rounding_math during manifestly constant evaluation.

            * g++.dg/cpp1z/constexpr-96862.C: New test.

    (cherry picked from commit 6641d6d3fe79113f8d9f3ced355aea79bffda822)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (11 preceding siblings ...)
  2020-09-11  7:47 ` cvs-commit at gcc dot gnu.org
@ 2020-09-16 19:23 ` cvs-commit at gcc dot gnu.org
  2021-07-27  5:34 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-16 19:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:25542b27aa6a75ad0f7316c3767c957cce912fb7

commit r9-8912-g25542b27aa6a75ad0f7316c3767c957cce912fb7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Sep 3 20:11:43 2020 +0200

    c++: Disable -frounding-math during manifestly constant evaluation
[PR96862]

    As discussed in the PR, fold-const.c punts on floating point constant
    evaluation if the result is inexact and -frounding-math is turned on.
          /* Don't constant fold this floating point operation if the
             result may dependent upon the run-time rounding mode and
             flag_rounding_math is set, or if GCC's software emulation
             is unable to accurately represent the result.  */
          if ((flag_rounding_math
               || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
              && (inexact || !real_identical (&result, &value)))
            return NULL_TREE;
    Jonathan said that we should be evaluating them anyway, e.g. conceptually
    as if they are done with the default rounding mode before user had a chance
    to change that, and e.g. in C in initializers it is also ignored.
    In fact, fold-const.c for C initializers turns off various other options:

    /* Perform constant folding and related simplification of initializer
       expression EXPR.  These behave identically to "fold_buildN" but ignore
       potential run-time traps and exceptions that fold must preserve.  */

      int saved_signaling_nans = flag_signaling_nans;\
      int saved_trapping_math = flag_trapping_math;\
      int saved_rounding_math = flag_rounding_math;\
      int saved_trapv = flag_trapv;\
      int saved_folding_initializer = folding_initializer;\
      flag_signaling_nans = 0;\
      flag_trapping_math = 0;\
      flag_rounding_math = 0;\
      flag_trapv = 0;\
      folding_initializer = 1;

      flag_signaling_nans = saved_signaling_nans;\
      flag_trapping_math = saved_trapping_math;\
      flag_rounding_math = saved_rounding_math;\
      flag_trapv = saved_trapv;\
      folding_initializer = saved_folding_initializer;

    So, shall cxx_eval_outermost_constant_expr instead turn off all those
    options (then warning_sentinel wouldn't be the right thing to use, but
given
    the 8 or how many return stmts in cxx_eval_outermost_constant_expr, we'd
    need a RAII class for this.  Not sure about the folding_initializer, that
    one is affecting complex multiplication and division constant evaluation
    somehow.

    2020-09-03  Jakub Jelinek  <jakub@redhat.com>

            PR c++/96862
            * constexpr.c (cxx_eval_outermost_constant_expr): Temporarily
disable
            flag_rounding_math during manifestly constant evaluation.

            * g++.dg/cpp1z/constexpr-96862.C: New test.

    (cherry picked from commit 6641d6d3fe79113f8d9f3ced355aea79bffda822)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (12 preceding siblings ...)
  2020-09-16 19:23 ` cvs-commit at gcc dot gnu.org
@ 2021-07-27  5:34 ` pinskia at gcc dot gnu.org
  2021-08-22  0:43 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27  5:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |glisse at gcc dot gnu.org

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 91099 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (13 preceding siblings ...)
  2021-07-27  5:34 ` pinskia at gcc dot gnu.org
@ 2021-08-22  0:43 ` pinskia at gcc dot gnu.org
  2021-10-27 13:11 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22  0:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-08-22
             Status|UNCONFIRMED                 |NEW

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (14 preceding siblings ...)
  2021-08-22  0:43 ` pinskia at gcc dot gnu.org
@ 2021-10-27 13:11 ` rguenth at gcc dot gnu.org
  2021-10-27 13:43 ` jakub at gcc dot gnu.org
  2022-12-25  7:19 ` pinskia at gcc dot gnu.org
  17 siblings, 0 replies; 19+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-27 13:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

--- Comment #14 from Richard Biener <rguenth at gcc dot gnu.org> ---
Is this now fixed?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (15 preceding siblings ...)
  2021-10-27 13:11 ` rguenth at gcc dot gnu.org
@ 2021-10-27 13:43 ` jakub at gcc dot gnu.org
  2022-12-25  7:19 ` pinskia at gcc dot gnu.org
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-27 13:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think so.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
  2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
                   ` (16 preceding siblings ...)
  2021-10-27 13:43 ` jakub at gcc dot gnu.org
@ 2022-12-25  7:19 ` pinskia at gcc dot gnu.org
  17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-25  7:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96862

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.3.0, 11.1.0, 9.4.0
      Known to fail|                            |10.2.0, 9.3.0
   Target Milestone|---                         |9.4

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-12-25  7:19 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31  9:41 [Bug libstdc++/96862] New: -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression Laurent.Rineau__gcc at normalesup dot org
2020-08-31  9:52 ` [Bug libstdc++/96862] " jakub at gcc dot gnu.org
2020-08-31 10:57 ` redi at gcc dot gnu.org
2020-08-31 11:12 ` jakub at gcc dot gnu.org
2020-08-31 13:06 ` [Bug c++/96862] " rguenth at gcc dot gnu.org
2020-08-31 13:17 ` Laurent.Rineau__gcc at normalesup dot org
2020-08-31 13:40 ` glisse at gcc dot gnu.org
2020-08-31 13:57 ` redi at gcc dot gnu.org
2020-08-31 14:06 ` jakub at gcc dot gnu.org
2020-08-31 14:22 ` glisse at gcc dot gnu.org
2020-08-31 14:29 ` jakub at gcc dot gnu.org
2020-09-03 18:12 ` cvs-commit at gcc dot gnu.org
2020-09-11  7:47 ` cvs-commit at gcc dot gnu.org
2020-09-16 19:23 ` cvs-commit at gcc dot gnu.org
2021-07-27  5:34 ` pinskia at gcc dot gnu.org
2021-08-22  0:43 ` pinskia at gcc dot gnu.org
2021-10-27 13:11 ` rguenth at gcc dot gnu.org
2021-10-27 13:43 ` jakub at gcc dot gnu.org
2022-12-25  7:19 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).