public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11
@ 2012-06-13 20:42 tmsriram at google dot com
  2012-08-07 22:34 ` [Bug c++/53661] [gcc-4.7/4.8 regression] " tmsriram at google dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: tmsriram at google dot com @ 2012-06-13 20:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

             Bug #: 53661
           Summary: Wrong narrowing conversion warning with -std=c++11
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tmsriram@google.com


test.cc

enum Code {
  SUCCESS = 0
};

Code a;

int r[] = {a};

$ g++ test.cc -c -std=c++11
test.cc:7:13:warning: narrowing conversion of ‘a’ from ‘Code’ to ‘int’ inside {
} [-Wnarrowing]
 int r[] = {a};


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
@ 2012-08-07 22:34 ` tmsriram at google dot com
  2012-09-13 23:40 ` paolo.carlini at oracle dot com
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tmsriram at google dot com @ 2012-08-07 22:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Sriraman Tallam <tmsriram at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |c++
            Summary|Wrong narrowing conversion  |[gcc-4.7/4.8 regression]
                   |warning with -std=c++11     |Wrong narrowing conversion
                   |                            |warning with -std=c++11

--- Comment #1 from Sriraman Tallam <tmsriram at google dot com> 2012-08-07 22:33:58 UTC ---
Tip of trunk still fails.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
  2012-08-07 22:34 ` [Bug c++/53661] [gcc-4.7/4.8 regression] " tmsriram at google dot com
@ 2012-09-13 23:40 ` paolo.carlini at oracle dot com
  2012-09-13 23:43 ` paolo.carlini at oracle dot com
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-13 23:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-13 23:40:22 UTC ---
Manuel, what do you think about this? I see the warning happening because the
underlying type of Code is unsigned int.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
  2012-08-07 22:34 ` [Bug c++/53661] [gcc-4.7/4.8 regression] " tmsriram at google dot com
  2012-09-13 23:40 ` paolo.carlini at oracle dot com
@ 2012-09-13 23:43 ` paolo.carlini at oracle dot com
  2012-09-14  6:05 ` manu at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-13 23:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-13 23:43:01 UTC ---
Actually adding Manuel in CC.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (2 preceding siblings ...)
  2012-09-13 23:43 ` paolo.carlini at oracle dot com
@ 2012-09-14  6:05 ` manu at gcc dot gnu.org
  2012-09-14  9:37 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: manu at gcc dot gnu.org @ 2012-09-14  6:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-09-14 06:05:09 UTC ---
(In reply to comment #2)
> Manuel, what do you think about this? I see the warning happening because the
> underlying type of Code is unsigned int.

Isn't this a warning mandated by the standard?


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (3 preceding siblings ...)
  2012-09-14  6:05 ` manu at gcc dot gnu.org
@ 2012-09-14  9:37 ` paolo.carlini at oracle dot com
  2012-09-14 13:46 ` jason at gcc dot gnu.org
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-14  9:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-14 09:37:00 UTC ---
Indeed, I think it is, unless something says that the underlying type must be
int, but I don't think how. I think this PR is invalid. Let's ask Jason, to be
safe.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (4 preceding siblings ...)
  2012-09-14  9:37 ` paolo.carlini at oracle dot com
@ 2012-09-14 13:46 ` jason at gcc dot gnu.org
  2012-09-14 13:49 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2012-09-14 13:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-09-14
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2012-09-14 13:46:12 UTC ---
This is a bug.  The values of Code (as per 7.2p7) are { 0, 1 }, and int can
represent both values, so the conversion is not a narrowing conversion.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (5 preceding siblings ...)
  2012-09-14 13:46 ` jason at gcc dot gnu.org
@ 2012-09-14 13:49 ` paolo.carlini at oracle dot com
  2012-09-14 14:07 ` manu at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-14 13:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-14 13:49:00 UTC ---
Ah, ah, I see, thanks.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (6 preceding siblings ...)
  2012-09-14 13:49 ` paolo.carlini at oracle dot com
@ 2012-09-14 14:07 ` manu at gcc dot gnu.org
  2012-09-14 16:28 ` harald at gigawatt dot nl
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: manu at gcc dot gnu.org @ 2012-09-14 14:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

--- Comment #8 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-09-14 14:07:21 UTC ---
Wconversion does not warn either, but it also does not warn for:

enum Code {
  SUCCESS=-1
};

Code a;
void foo(void)
{
  unsigned int r;
  r = a;
}

Perhaps the code for handling this could be shared between Wconversion and
Wnarrowing (they warn in different cases but finding out these cases probably
requires similar code).


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (7 preceding siblings ...)
  2012-09-14 14:07 ` manu at gcc dot gnu.org
@ 2012-09-14 16:28 ` harald at gigawatt dot nl
  2012-09-17 15:42 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: harald at gigawatt dot nl @ 2012-09-14 16:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #9 from Harald van Dijk <harald at gigawatt dot nl> 2012-09-14 16:28:40 UTC ---
Sorry for butting in, but is this really a bug?

7.2p5 says "Each enumeration defines a type that is different from all other
types. Each enumeration also has an underlying type. The underlying type can be
explicitly specified using enum-base; if not explicitly specified, the
underlying type of a scoped enumeration type is int. In these cases, the
underlying type is said to be fixed."

This is an unscoped enumeration type without an enum-base, so the underlying
type is not fixed. 7.2p7 starts as "For an enumeration whose underlying type is
fixed,", so does not apply. 7.2p6 does apply, but the relevant text of 7.2p7
that would make this code valid isn't present there.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (8 preceding siblings ...)
  2012-09-14 16:28 ` harald at gigawatt dot nl
@ 2012-09-17 15:42 ` jason at gcc dot gnu.org
  2012-09-17 16:06 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2012-09-17 15:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

--- Comment #10 from Jason Merrill <jason at gcc dot gnu.org> 2012-09-17 15:42:41 UTC ---
(In reply to comment #9)
> 7.2p7 starts as "For an enumeration whose underlying type is
> fixed,", so does not apply.

That's just the first sentence; the rest of p7 does apply.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (9 preceding siblings ...)
  2012-09-17 15:42 ` jason at gcc dot gnu.org
@ 2012-09-17 16:06 ` jason at gcc dot gnu.org
  2012-09-17 16:25 ` harald at gigawatt dot nl
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2012-09-17 16:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

--- Comment #11 from Jason Merrill <jason at gcc dot gnu.org> 2012-09-17 16:06:10 UTC ---
Author: jason
Date: Mon Sep 17 16:06:03 2012
New Revision: 191395

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191395
Log:
    PR c++/53661
    * typeck2.c (check_narrowing): Avoid false positives on conversion
    from enumeral type.

Added:
    trunk/gcc/testsuite/g++.dg/init/aggr9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck2.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (10 preceding siblings ...)
  2012-09-17 16:06 ` jason at gcc dot gnu.org
@ 2012-09-17 16:25 ` harald at gigawatt dot nl
  2012-09-17 16:42 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: harald at gigawatt dot nl @ 2012-09-17 16:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

--- Comment #12 from Harald van Dijk <harald at gigawatt dot nl> 2012-09-17 16:25:09 UTC ---
Oops, quite right, sorry about that.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (12 preceding siblings ...)
  2012-09-17 16:42 ` jason at gcc dot gnu.org
@ 2012-09-17 16:42 ` jason at gcc dot gnu.org
  2012-09-17 16:43 ` jason at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2012-09-17 16:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> 2012-09-17 16:41:49 UTC ---
Author: jason
Date: Mon Sep 17 16:41:41 2012
New Revision: 191398

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191398
Log:
    PR c++/53661
    * typeck2.c (check_narrowing): Avoid false positives on conversion
    from enumeral type.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/init/aggr9.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/typeck2.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (11 preceding siblings ...)
  2012-09-17 16:25 ` harald at gigawatt dot nl
@ 2012-09-17 16:42 ` jason at gcc dot gnu.org
  2012-09-17 16:42 ` jason at gcc dot gnu.org
  2012-09-17 16:43 ` jason at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2012-09-17 16:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.2

--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> 2012-09-17 16:41:49 UTC ---
Author: jason
Date: Mon Sep 17 16:41:41 2012
New Revision: 191398

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191398
Log:
    PR c++/53661
    * typeck2.c (check_narrowing): Avoid false positives on conversion
    from enumeral type.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/init/aggr9.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/typeck2.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog

--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> 2012-09-17 16:42:44 UTC ---
Fixed for 4.7.2.


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

* [Bug c++/53661] [gcc-4.7/4.8 regression] Wrong narrowing conversion warning with -std=c++11
  2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
                   ` (13 preceding siblings ...)
  2012-09-17 16:42 ` jason at gcc dot gnu.org
@ 2012-09-17 16:43 ` jason at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2012-09-17 16:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53661

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.2

--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> 2012-09-17 16:42:44 UTC ---
Fixed for 4.7.2.


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

end of thread, other threads:[~2012-09-17 16:43 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-13 20:42 [Bug c/53661] New: Wrong narrowing conversion warning with -std=c++11 tmsriram at google dot com
2012-08-07 22:34 ` [Bug c++/53661] [gcc-4.7/4.8 regression] " tmsriram at google dot com
2012-09-13 23:40 ` paolo.carlini at oracle dot com
2012-09-13 23:43 ` paolo.carlini at oracle dot com
2012-09-14  6:05 ` manu at gcc dot gnu.org
2012-09-14  9:37 ` paolo.carlini at oracle dot com
2012-09-14 13:46 ` jason at gcc dot gnu.org
2012-09-14 13:49 ` paolo.carlini at oracle dot com
2012-09-14 14:07 ` manu at gcc dot gnu.org
2012-09-14 16:28 ` harald at gigawatt dot nl
2012-09-17 15:42 ` jason at gcc dot gnu.org
2012-09-17 16:06 ` jason at gcc dot gnu.org
2012-09-17 16:25 ` harald at gigawatt dot nl
2012-09-17 16:42 ` jason at gcc dot gnu.org
2012-09-17 16:42 ` jason at gcc dot gnu.org
2012-09-17 16:43 ` 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).