[Bug c++/96452] Narrowing conversion is not rejected

2021-09-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|INVALID |DUPLICATE

--- Comment #8 from Andrew Pinski  ---


*** This bug has been marked as a duplicate of bug 55783 ***

[Bug c++/96452] Narrowing conversion is not rejected

2020-08-04 Thread antoshkka at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

--- Comment #7 from Antony Polukhin  ---
(In reply to Jonathan Wakely from comment #6)
> Your understanding of what a compiler needs to do for ill-formed programs is
> wrong.

You're right, thank you!

[Bug c++/96452] Narrowing conversion is not rejected

2020-08-04 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

--- Comment #6 from Jonathan Wakely  ---
Your understanding of what a compiler needs to do for ill-formed programs is
wrong.

[intro.compliance]

If a program contains a violation of any diagnosable rule or an occurrence of a
construct described in this document as “conditionally-supported” when the
implementation does not support that construct, a conforming implementation
shall issue at least one diagnostic message.

[Bug c++/96452] Narrowing conversion is not rejected

2020-08-04 Thread antoshkka at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

--- Comment #5 from Antony Polukhin  ---
Hm... My reading of http://eel.is/c++draft/dcl.init.list#3.9 is that the
program is ill-formed for narrowing conversions. And
http://eel.is/c++draft/dcl.init.list#7.2 states that conversion from double to
float is a narrowing one, except where the source is a constant expression.

Am I missing something?

[Bug c++/96452] Narrowing conversion is not rejected

2020-08-04 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

--- Comment #4 from Jonathan Wakely  ---
https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wnarrowing

For C++11 and later standards, narrowing conversions are diagnosed by default,
as required by the standard. A narrowing conversion from a constant produces an
error, and a narrowing conversion from a non-constant produces a warning, but
-Wno-narrowing suppresses the diagnostic. Note that this does not affect the
meaning of well-formed code; narrowing conversions are still considered
ill-formed in SFINAE contexts.

[Bug c++/96452] Narrowing conversion is not rejected

2020-08-04 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

--- Comment #3 from Jonathan Wakely  ---
(In reply to Andrew Pinski from comment #1)
> Use -pedantic-errors to get the error message instead.

Or -Werror=narrowing

> We allow this extension by default.

It's not an extension, it's standard-conforming behaviour.

[Bug c++/96452] Narrowing conversion is not rejected

2020-08-04 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

--- Comment #2 from Jonathan Wakely  ---
Not a bug, the standard requires a diagnostic, a warning is a diagnostic.

There are loads of existing bugs about this in bugzilla. GCC produces errors
for constants where narrowing is known to change the value, and a warning
otherwise.

[Bug c++/96452] Narrowing conversion is not rejected

2020-08-04 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #1 from Andrew Pinski  ---
Use -pedantic-errors to get the error message instead.
We allow this extension by default.