public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28031]  New: [4.2 regression] bogus jump to case label crosses initialization error
@ 2006-06-14 16:49 tbm at cyrius dot com
  2006-06-14 16:52 ` [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: tbm at cyrius dot com @ 2006-06-14 16:49 UTC (permalink / raw)
  To: gcc-bugs

I'm pretty sure the following error is bogus.  I don't see anything invalid in
this test case and it worked with g++ 4.1.  It also works with gcc 4.2 20060419
but not with the current version.

(sid)1053:tbm@reyes: ~] /usr/lib/gcc-snapshot/bin/g++ -c test.c
test.c: In function 'int main()':
test.c:16: error: jump to case label
test.c:13: error:   crosses initialization of 'terror <anonymous>'
zsh: exit 1     /usr/lib/gcc-snapshot/bin/g++ -c test.c
(sid)1054:tbm@reyes: ~] cat test.c
typedef struct terror_struct
{
    int  code;
    char msg[64];
} terror;

int main(void) {
  terror e;
  e = (terror){0,""};

  switch(1) {
  case 1:
    e = (terror){400,"Bad username"};
    break;

  case 2:
    e = (terror){503,"Turboing, connect later"};
    break;

  }
}


-- 
           Summary: [4.2 regression] bogus jump to case label crosses
                    initialization error
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tbm at cyrius dot com


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


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

* [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers
  2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
@ 2006-06-14 16:52 ` pinskia at gcc dot gnu dot org
  2006-06-14 16:54 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-06-14 16:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-06-14 16:49 -------
This is caused by the C99 initializer extension to C++.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org, mmitchel at gcc dot gnu
                   |                            |dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
      Known to fail|                            |4.2.0
   Last reconfirmed|0000-00-00 00:00:00         |2006-06-14 16:49:08
               date|                            |
            Summary|[4.2 regression] bogus jump |[4.2 regression] bogus jump
                   |to case label crosses       |to case label crosses
                   |initialization error        |initialization error with
                   |                            |C99 anonymous initializers
   Target Milestone|---                         |4.2.0


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


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

* [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers
  2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
  2006-06-14 16:52 ` [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers pinskia at gcc dot gnu dot org
@ 2006-06-14 16:54 ` pinskia at gcc dot gnu dot org
  2006-06-14 16:56 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-06-14 16:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-06-14 16:52 -------
Here is a reduced testcase:
typedef struct terror_struct {int c; } terror;
int main(void)
{
  terror e;
  switch(1)
  {
  case 1:
    e = (terror){400};
  case 2:
    break;
  }
}


-- 


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


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

* [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers
  2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
  2006-06-14 16:52 ` [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers pinskia at gcc dot gnu dot org
  2006-06-14 16:54 ` pinskia at gcc dot gnu dot org
@ 2006-06-14 16:56 ` pinskia at gcc dot gnu dot org
  2006-07-17  2:41 ` mmitchel at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-06-14 16:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-06-14 16:53 -------
This was caused by:
2006-05-24  Mark Mitchell  <mark@codesourcery.com>

        PR c++/20103


-- 


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


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

* [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers
  2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
                   ` (2 preceding siblings ...)
  2006-06-14 16:56 ` pinskia at gcc dot gnu dot org
@ 2006-07-17  2:41 ` mmitchel at gcc dot gnu dot org
  2006-07-21  1:42 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-07-17  2:41 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


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


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

* [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers
  2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
                   ` (3 preceding siblings ...)
  2006-07-17  2:41 ` mmitchel at gcc dot gnu dot org
@ 2006-07-21  1:42 ` mmitchel at gcc dot gnu dot org
  2008-10-02 13:57 ` cvoica at gmail dot com
  2008-10-02 14:32 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-07-21  1:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from mmitchel at gcc dot gnu dot org  2006-07-21 01:42 -------
In C99, a compound literal in the body of a function has automatic storage
duration associated with the enclosing block.  That's what the C++ front end
now does.  In that context, the error given is entirely reasonable; it's the
same error you would get for:

  switch (n) {
    int i = 3;
    case 1:
      ;
  }

since here, "i" is a variable in scope.  (C99 doesn't disallow this case,
apparently, but C++ does.)

The counter-argument is that perhaps in C++ compound-literals should have
storage duration that lasts only until the enclosing full expression.  However,
that would be an incompatibility with C99, as things like:

  struct S *p = &(struct S){3};
  p->i = 7;

would then be valid C99 (as the object is in scope), but undefined in C++ (as
the anonymous variable would have gone out of scope).  

Therefore, I believe the current C++ implementation to make the most sense,
absent clear direction from the ISO C++ committee.


-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers
  2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
                   ` (4 preceding siblings ...)
  2006-07-21  1:42 ` mmitchel at gcc dot gnu dot org
@ 2008-10-02 13:57 ` cvoica at gmail dot com
  2008-10-02 14:32 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: cvoica at gmail dot com @ 2008-10-02 13:57 UTC (permalink / raw)
  To: gcc-bugs

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



------- Comment #5 from cvoica at gmail dot com  2008-10-02 13:56 -------
I was trying to compile some code and got this error and thats how I found this
bug.
It seems strange to me that I cannot use a switch within a case branch and the
use the plain std::string.

Testcase:
1. This is working:
#include<iostream>
using namespace std;

int main(){
int i =0;
switch(i){
        case 0:
                break;
        case 1:
                string s;
                break;
}
return 0;
}
ws6-126:~cvo> g++ switchtest.cxx 
ws6-126:~cvo> g++ --version
g++ (GCC) 4.2.1 (SUSE Linux)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


2. This is not working:

#include<iostream>
using namespace std;

int main(){
int i =0;
switch(i){
        case 0:
                int j=0;
                switch(j){
                        case 0:
                         break;
                }
                break;
        case 1:
                string s;
                break;
}
return 0;
}
ws6-126:~cvo> g++ switchtest.cxx 
switchtest.cxx: In function ‘int main()’:
switchtest.cxx:14: error: jump to case label
switchtest.cxx:8: error:   crosses initialization of ‘int j’


-- 

cvoica at gmail dot com changed:

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


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


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

* [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers
  2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
                   ` (5 preceding siblings ...)
  2008-10-02 13:57 ` cvoica at gmail dot com
@ 2008-10-02 14:32 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2008-10-02 14:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from mmitchel at gcc dot gnu dot org  2008-10-02 14:30 -------
You're getting an error because your code is invalid for the reason the error
message states.  The reason is that if the value of "i" is 1, you will end up
in the "case 1" part with "j" uninitialized.  You can put the entire body of
the outer "case 0" inside braces, so that "j" is not in scope in the "case 1"
part; that will eliminate the error.


-- 


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


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

end of thread, other threads:[~2008-10-02 14:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-14 16:49 [Bug c++/28031] New: [4.2 regression] bogus jump to case label crosses initialization error tbm at cyrius dot com
2006-06-14 16:52 ` [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers pinskia at gcc dot gnu dot org
2006-06-14 16:54 ` pinskia at gcc dot gnu dot org
2006-06-14 16:56 ` pinskia at gcc dot gnu dot org
2006-07-17  2:41 ` mmitchel at gcc dot gnu dot org
2006-07-21  1:42 ` mmitchel at gcc dot gnu dot org
2008-10-02 13:57 ` cvoica at gmail dot com
2008-10-02 14:32 ` mmitchel 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).