public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "glisse at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/96862] -frounding-math -std=c++2a error: '(1.29e+2 * 6.9314718055994529e-1)' is not a constant expression
Date: Mon, 31 Aug 2020 13:40:03 +0000	[thread overview]
Message-ID: <bug-96862-4-E9HTTkQf9V@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96862-4@http.gcc.gnu.org/bugzilla/>

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.

  parent reply	other threads:[~2020-08-31 13:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31  9:41 [Bug libstdc++/96862] New: " 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-96862-4-E9HTTkQf9V@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).