public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39371]  New: Incorrectly rejects switch((unsigned int)boolvar)
@ 2009-03-05  0:00 foo at mailinator dot com
  2009-03-05 10:36 ` [Bug c++/39371] [4.2/4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: foo at mailinator dot com @ 2009-03-05  0:00 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

void foo(bool b)
{
    switch ((unsigned int)b) {
        case 1:
        case 2: ;
    }
}

% g++ test.cc
test.cc: In function ‘void foo(bool)’:
test.cc:6: error: duplicate case value
test.cc:5: error: previously used here

The bug only appears with casts to (unsigned int) or wider; casts to (int),
(unsigned short), etc., work as expected.

Reproduces with GCC versions 4.2.4 and 4.3.2.


-- 
           Summary: Incorrectly rejects switch((unsigned int)boolvar)
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: foo at mailinator dot com


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


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

* [Bug c++/39371] [4.2/4.3/4.4 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
@ 2009-03-05 10:36 ` rguenth at gcc dot gnu dot org
  2009-03-08 15:41 ` rguenth at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-05 10:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-03-05 10:35 -------
Confirmed.  2.95.4 only (incorrectly) warned about an out-of-range case value:

/space/rguenther/install/gcc-2.95/bin/g++ -S t.C
t.C: In function `void foo(bool)':
t.C:5: warning: case value out of range


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |rejects-valid
      Known to fail|                            |3.3.6
      Known to work|                            |2.95.4
   Last reconfirmed|0000-00-00 00:00:00         |2009-03-05 10:35:56
               date|                            |
            Summary|Incorrectly rejects         |[4.2/4.3/4.4 Regression]
                   |switch((unsigned            |Incorrectly rejects
                   |int)boolvar)                |switch((unsigned
                   |                            |int)boolvar)
   Target Milestone|---                         |4.2.5


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


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

* [Bug c++/39371] [4.2/4.3/4.4 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
  2009-03-05 10:36 ` [Bug c++/39371] [4.2/4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
@ 2009-03-08 15:41 ` rguenth at gcc dot gnu dot org
  2009-03-09  8:22 ` jakub at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-08 15:41 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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


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

* [Bug c++/39371] [4.2/4.3/4.4 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
  2009-03-05 10:36 ` [Bug c++/39371] [4.2/4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
  2009-03-08 15:41 ` rguenth at gcc dot gnu dot org
@ 2009-03-09  8:22 ` jakub at gcc dot gnu dot org
  2009-03-09 10:31 ` jakub at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-03-09  8:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2009-03-09 08:22 -------
This isn't related to just bool, e.g.:
void
foo (unsigned char b)
{
  switch ((unsigned int) b)
    {
    case 1:
    case 257:
      break;
    }
}
also results in
pr39371-2.C:7: warning: large integer implicitly truncated to unsigned type
pr39371-2.C:7: error: duplicate case value
pr39371-2.C:6: error: previously used here

In C both testcases are fine.


-- 


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


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

* [Bug c++/39371] [4.2/4.3/4.4 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (2 preceding siblings ...)
  2009-03-09  8:22 ` jakub at gcc dot gnu dot org
@ 2009-03-09 10:31 ` jakub at gcc dot gnu dot org
  2009-03-09 19:34 ` jakub at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-03-09 10:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2009-03-09 10:31 -------
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00463.html


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2009-
                   |                            |03/msg00463.html
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2009-03-05 10:35:56         |2009-03-09 10:31:06
               date|                            |


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


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

* [Bug c++/39371] [4.2/4.3/4.4 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (3 preceding siblings ...)
  2009-03-09 10:31 ` jakub at gcc dot gnu dot org
@ 2009-03-09 19:34 ` jakub at gcc dot gnu dot org
  2009-03-09 19:36 ` [Bug c++/39371] [4.2/4.3 " jakub at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-03-09 19:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2009-03-09 19:34 -------
Subject: Bug 39371

Author: jakub
Date: Mon Mar  9 19:34:10 2009
New Revision: 144732

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144732
Log:
        PR c++/39371
        * semantics.c (finish_switch_cond): Don't call get_unwidened.
        * decl.c (finish_case_label): Pass SWITCH_STMT_TYPE as 3rd argument
        instead of TREE_TYPE (cond).

        * g++.dg/opt/switch2.C: Add -w to dg-options.
        * g++.dg/warn/Wswitch-1.C: Adjust expected warnings.
        * g++.dg/warn/switch1.C: New test.
        * g++.dg/other/switch3.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/other/switch3.C
    trunk/gcc/testsuite/g++.dg/warn/switch1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/opt/switch2.C
    trunk/gcc/testsuite/g++.dg/warn/Wswitch-1.C


-- 


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


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

* [Bug c++/39371] [4.2/4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (4 preceding siblings ...)
  2009-03-09 19:34 ` jakub at gcc dot gnu dot org
@ 2009-03-09 19:36 ` jakub at gcc dot gnu dot org
  2009-03-31 21:11 ` [Bug c++/39371] [4.3 " jsm28 at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-03-09 19:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2009-03-09 19:35 -------
Fixed on the trunk so far.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|2.95.4                      |2.95.4 4.4.0
            Summary|[4.2/4.3/4.4 Regression]    |[4.2/4.3 Regression]
                   |Incorrectly rejects         |Incorrectly rejects
                   |switch((unsigned            |switch((unsigned
                   |int)boolvar)                |int)boolvar)


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


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

* [Bug c++/39371] [4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (5 preceding siblings ...)
  2009-03-09 19:36 ` [Bug c++/39371] [4.2/4.3 " jakub at gcc dot gnu dot org
@ 2009-03-31 21:11 ` jsm28 at gcc dot gnu dot org
  2009-06-04 11:16 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2009-03-31 21:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jsm28 at gcc dot gnu dot org  2009-03-31 21:10 -------
Closing 4.2 branch.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.2/4.3 Regression]        |[4.3 Regression] Incorrectly
                   |Incorrectly rejects         |rejects switch((unsigned
                   |switch((unsigned            |int)boolvar)
                   |int)boolvar)                |
   Target Milestone|4.2.5                       |4.3.4


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


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

* [Bug c++/39371] [4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (6 preceding siblings ...)
  2009-03-31 21:11 ` [Bug c++/39371] [4.3 " jsm28 at gcc dot gnu dot org
@ 2009-06-04 11:16 ` rguenth at gcc dot gnu dot org
  2009-06-04 11:22 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-04 11:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2009-06-04 11:16 -------
*** Bug 40335 has been marked as a duplicate of this bug. ***


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |shenrfen at gmail dot com


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


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

* [Bug c++/39371] [4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (7 preceding siblings ...)
  2009-06-04 11:16 ` rguenth at gcc dot gnu dot org
@ 2009-06-04 11:22 ` rguenth at gcc dot gnu dot org
  2009-06-04 12:35 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-04 11:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2009-06-04 11:21 -------
I'm testing a backport.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|jakub at gcc dot gnu dot org|rguenth at gcc dot gnu dot
                   |                            |org
           Keywords|                            |wrong-code


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


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

* [Bug c++/39371] [4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (8 preceding siblings ...)
  2009-06-04 11:22 ` rguenth at gcc dot gnu dot org
@ 2009-06-04 12:35 ` rguenth at gcc dot gnu dot org
  2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-04 12:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2009-06-04 12:35 -------
Subject: Bug 39371

Author: rguenth
Date: Thu Jun  4 12:35:25 2009
New Revision: 148165

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148165
Log:
2009-06-04  Richard Guenther  <rguenther@suse.de>

        Backport from mainline
        2009-03-09  Jakub Jelinek  <jakub@redhat.com>

        PR c++/39371
        * semantics.c (finish_switch_cond): Don't call get_unwidened.
        * decl.c (finish_case_label): Pass SWITCH_STMT_TYPE as 3rd argument
        instead of TREE_TYPE (cond).

        * g++.dg/opt/switch2.C: Add -w to dg-options.
        * g++.dg/warn/Wswitch-1.C: Adjust expected warnings.
        * g++.dg/warn/switch1.C: New test.
        * g++.dg/other/switch3.C: New test.
        * g++.dg/torture/pr40335.C: New testcase.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/other/switch3.C
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/torture/pr40335.C
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/warn/switch1.C
Modified:
    branches/gcc-4_3-branch/gcc/cp/ChangeLog
    branches/gcc-4_3-branch/gcc/cp/decl.c
    branches/gcc-4_3-branch/gcc/cp/semantics.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/opt/switch2.C
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/warn/Wswitch-1.C


-- 


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


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

* [Bug c++/39371] [4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (10 preceding siblings ...)
  2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
@ 2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
  2009-06-04 12:42 ` rguenth at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-04 12:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2009-06-04 12:38 -------
Subject: Bug 39371

Author: rguenth
Date: Thu Jun  4 12:37:48 2009
New Revision: 148166

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148166
Log:
2009-06-04  Richard Guenther  <rguenther@suse.de>

        PR c++/39371
        * g++.dg/torture/pr40335.C: New testcase.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/torture/pr40335.C
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/39371] [4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (9 preceding siblings ...)
  2009-06-04 12:35 ` rguenth at gcc dot gnu dot org
@ 2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
  2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
  2009-06-04 12:42 ` rguenth at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-04 12:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from rguenth at gcc dot gnu dot org  2009-06-04 12:38 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to fail|3.3.6                       |3.3.6 4.3.3
      Known to work|2.95.4 4.4.0                |2.95.4 4.3.4 4.4.0
         Resolution|                            |FIXED


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


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

* [Bug c++/39371] [4.3 Regression] Incorrectly rejects switch((unsigned int)boolvar)
  2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
                   ` (11 preceding siblings ...)
  2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
@ 2009-06-04 12:42 ` rguenth at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-04 12:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from rguenth at gcc dot gnu dot org  2009-06-04 12:41 -------
Subject: Bug 39371

Author: rguenth
Date: Thu Jun  4 12:41:31 2009
New Revision: 148167

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148167
Log:
2009-06-04  Richard Guenther  <rguenther@suse.de>

        PR c++/39371
        * g++.dg/torture/pr40335.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr40335.C
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

end of thread, other threads:[~2009-06-04 12:42 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-05  0:00 [Bug c++/39371] New: Incorrectly rejects switch((unsigned int)boolvar) foo at mailinator dot com
2009-03-05 10:36 ` [Bug c++/39371] [4.2/4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
2009-03-08 15:41 ` rguenth at gcc dot gnu dot org
2009-03-09  8:22 ` jakub at gcc dot gnu dot org
2009-03-09 10:31 ` jakub at gcc dot gnu dot org
2009-03-09 19:34 ` jakub at gcc dot gnu dot org
2009-03-09 19:36 ` [Bug c++/39371] [4.2/4.3 " jakub at gcc dot gnu dot org
2009-03-31 21:11 ` [Bug c++/39371] [4.3 " jsm28 at gcc dot gnu dot org
2009-06-04 11:16 ` rguenth at gcc dot gnu dot org
2009-06-04 11:22 ` rguenth at gcc dot gnu dot org
2009-06-04 12:35 ` rguenth at gcc dot gnu dot org
2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
2009-06-04 12:38 ` rguenth at gcc dot gnu dot org
2009-06-04 12:42 ` rguenth at gcc dot gnu dot 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).