public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96452] New: Narrowing conversion is not rejected
@ 2020-08-04 8:36 antoshkka at gmail dot com
2020-08-04 10:00 ` [Bug c++/96452] " pinskia at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: antoshkka at gmail dot com @ 2020-08-04 8:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
Bug ID: 96452
Summary: Narrowing conversion is not rejected
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
Consider the example:
float test_main(double d) {
float f2{d};
return f2;
}
Narrowing of double to float in brace-init is not rejected, only a warning is
issued.
Godbolt playground: https://godbolt.org/z/fzPT8r
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
@ 2020-08-04 10:00 ` pinskia at gcc dot gnu.org
2020-08-04 10:05 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-08-04 10:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Use -pedantic-errors to get the error message instead.
We allow this extension by default.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
2020-08-04 10:00 ` [Bug c++/96452] " pinskia at gcc dot gnu.org
@ 2020-08-04 10:05 ` redi at gcc dot gnu.org
2020-08-04 10:06 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-04 10:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
2020-08-04 10:00 ` [Bug c++/96452] " pinskia at gcc dot gnu.org
2020-08-04 10:05 ` redi at gcc dot gnu.org
@ 2020-08-04 10:06 ` redi at gcc dot gnu.org
2020-08-04 10:11 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-04 10:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
` (2 preceding siblings ...)
2020-08-04 10:06 ` redi at gcc dot gnu.org
@ 2020-08-04 10:11 ` redi at gcc dot gnu.org
2020-08-04 11:53 ` antoshkka at gmail dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-04 10:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
` (3 preceding siblings ...)
2020-08-04 10:11 ` redi at gcc dot gnu.org
@ 2020-08-04 11:53 ` antoshkka at gmail dot com
2020-08-04 14:19 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: antoshkka at gmail dot com @ 2020-08-04 11:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
--- Comment #5 from Antony Polukhin <antoshkka at gmail dot com> ---
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?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
` (4 preceding siblings ...)
2020-08-04 11:53 ` antoshkka at gmail dot com
@ 2020-08-04 14:19 ` redi at gcc dot gnu.org
2020-08-04 17:21 ` antoshkka at gmail dot com
2021-09-16 21:38 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-04 14:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
` (5 preceding siblings ...)
2020-08-04 14:19 ` redi at gcc dot gnu.org
@ 2020-08-04 17:21 ` antoshkka at gmail dot com
2021-09-16 21:38 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: antoshkka at gmail dot com @ 2020-08-04 17:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
--- Comment #7 from Antony Polukhin <antoshkka at gmail dot com> ---
(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!
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/96452] Narrowing conversion is not rejected
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
` (6 preceding siblings ...)
2020-08-04 17:21 ` antoshkka at gmail dot com
@ 2021-09-16 21:38 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-16 21:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96452
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |DUPLICATE
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** This bug has been marked as a duplicate of bug 55783 ***
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-09-16 21:38 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-04 8:36 [Bug c++/96452] New: Narrowing conversion is not rejected antoshkka at gmail dot com
2020-08-04 10:00 ` [Bug c++/96452] " pinskia at gcc dot gnu.org
2020-08-04 10:05 ` redi at gcc dot gnu.org
2020-08-04 10:06 ` redi at gcc dot gnu.org
2020-08-04 10:11 ` redi at gcc dot gnu.org
2020-08-04 11:53 ` antoshkka at gmail dot com
2020-08-04 14:19 ` redi at gcc dot gnu.org
2020-08-04 17:21 ` antoshkka at gmail dot com
2021-09-16 21:38 ` 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).