public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49577] New: [C++0x] narrowing conversion not rejected
@ 2011-06-29 12:38 redi at gcc dot gnu.org
2011-06-29 12:43 ` [Bug c++/49577] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-06-29 12:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49577
Summary: [C++0x] narrowing conversion not rejected
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: redi@gcc.gnu.org
CC: jason@gcc.gnu.org
unsigned u{ -1 };
char c = char{ u };
I believe this should be rejected because char{u} is a narrowing conversion and
the FDIS says in [dcl.init.list]/3:
- Otherwise, if the initializer list has a single element, the object or
reference is initialized from that element; if a narrowing conversion (see
below) is required to convert the element to T, the program is ill-formed.
These are correctly rejected:
char c1{ u };
char c2 = { u };
char* p = new char{ u };
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/49577] [C++0x] narrowing conversion not rejected
2011-06-29 12:38 [Bug c++/49577] New: [C++0x] narrowing conversion not rejected redi at gcc dot gnu.org
@ 2011-06-29 12:43 ` redi at gcc dot gnu.org
2011-06-29 12:49 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-06-29 12:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49577
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-06-29 12:43:16 UTC ---
... or does this not count as a narrowing conversion because it's not an
implicit conversion?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/49577] [C++0x] narrowing conversion not rejected
2011-06-29 12:38 [Bug c++/49577] New: [C++0x] narrowing conversion not rejected redi at gcc dot gnu.org
2011-06-29 12:43 ` [Bug c++/49577] " redi at gcc dot gnu.org
@ 2011-06-29 12:49 ` redi at gcc dot gnu.org
2011-06-29 12:55 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-06-29 12:49 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49577
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-06-29 12:49:07 UTC ---
G++ also accepts this, which the example in [dcl.init.list]/7 says is an error:
unsigned int ui1 = {-1}; // error: narrows
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/49577] [C++0x] narrowing conversion not rejected
2011-06-29 12:38 [Bug c++/49577] New: [C++0x] narrowing conversion not rejected redi at gcc dot gnu.org
2011-06-29 12:43 ` [Bug c++/49577] " redi at gcc dot gnu.org
2011-06-29 12:49 ` redi at gcc dot gnu.org
@ 2011-06-29 12:55 ` redi at gcc dot gnu.org
2011-08-02 20:01 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-06-29 12:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49577
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-06-29 12:54:54 UTC ---
And the following line in the same example:
signed int si1 =
{ (unsigned int)-1 }; // error: narrows
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/49577] [C++0x] narrowing conversion not rejected
2011-06-29 12:38 [Bug c++/49577] New: [C++0x] narrowing conversion not rejected redi at gcc dot gnu.org
` (2 preceding siblings ...)
2011-06-29 12:55 ` redi at gcc dot gnu.org
@ 2011-08-02 20:01 ` jason at gcc dot gnu.org
2011-08-02 21:11 ` jason at gcc dot gnu.org
2011-08-02 21:34 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-02 20:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49577
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2011.08.02 20:00:06
AssignedTo|unassigned at gcc dot |jason at gcc dot gnu.org
|gnu.org |
Ever Confirmed|0 |1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/49577] [C++0x] narrowing conversion not rejected
2011-06-29 12:38 [Bug c++/49577] New: [C++0x] narrowing conversion not rejected redi at gcc dot gnu.org
` (3 preceding siblings ...)
2011-08-02 20:01 ` jason at gcc dot gnu.org
@ 2011-08-02 21:11 ` jason at gcc dot gnu.org
2011-08-02 21:34 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-02 21:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49577
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-08-02 21:09:20 UTC ---
Author: jason
Date: Tue Aug 2 21:09:17 2011
New Revision: 177215
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=177215
Log:
PR c++/49577
* typeck2.c (check_narrowing): Check unsigned mismatch.
* semantics.c (finish_compound_literal): check_narrowing.
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/semantics.c
trunk/gcc/cp/typeck2.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/cpp0x/initlist5.C
trunk/gcc/testsuite/g++.dg/opt/range-test-1.C
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/49577] [C++0x] narrowing conversion not rejected
2011-06-29 12:38 [Bug c++/49577] New: [C++0x] narrowing conversion not rejected redi at gcc dot gnu.org
` (4 preceding siblings ...)
2011-08-02 21:11 ` jason at gcc dot gnu.org
@ 2011-08-02 21:34 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-02 21:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49577
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.7.0
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-08-02 21:33:02 UTC ---
Fixed for 4.7.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-08-02 21:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-29 12:38 [Bug c++/49577] New: [C++0x] narrowing conversion not rejected redi at gcc dot gnu.org
2011-06-29 12:43 ` [Bug c++/49577] " redi at gcc dot gnu.org
2011-06-29 12:49 ` redi at gcc dot gnu.org
2011-06-29 12:55 ` redi at gcc dot gnu.org
2011-08-02 20:01 ` jason at gcc dot gnu.org
2011-08-02 21:11 ` jason at gcc dot gnu.org
2011-08-02 21:34 ` jason 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).