public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21487] New: new object affectation in a switch
@ 2005-05-10 12:33 sebmaestro at hotmail dot com
  2005-05-10 13:12 ` [Bug c++/21487] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sebmaestro at hotmail dot com @ 2005-05-10 12:33 UTC (permalink / raw)
  To: gcc-bugs

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

what follows (version, command line, source and .ii) seems to be a bug.

if you need something else -> sebmaestro@hotmail.com.

"bravo et merci quand même pour votre bon boulot !"

seb.

------    Command lines :   ---------

seb$ g++ --version
g++ (GCC) 3.3.6 (Debian 1:3.3.6-4)
Copyright (C) 2003 Free Software Foundation, Inc.
Ce logiciel est libre; voir les sources pour les conditions de copie.  Il n'y a PAS
GARANTIE; ni implicite pour le MARCHANDAGE ou pour un BUT PARTICULIER.

seb$ g++ -Wall -save-temps -o test makebug.cpp 
makebug.cpp: Dans function « int main(int, char**) »:
makebug.cpp:42: error: saut à l'étiquette du « case »
makebug.cpp:40: error:   crosses initialization of `Thing*str'
makebug.cpp:44: error: saut à l'étiquette du « case »
makebug.cpp:40: error:   crosses initialization of `Thing*str'
makebug.cpp:40: attention : unused variable `Thing*str'

----------  source code: (makebug.cpp) -----------  

class Thing {
public:
  Thing() {
  }
};

int main (int argc, char ** argv){

  if (argc == 1) {
    return 0;
  }

  int truc = 0;

  
  switch (truc) {
    
  case 0:
    break;
  case 1:
    Thing *th;
    th = new Thing();
    break;
  case 2:
    break;
  case 3:
    break;


  }




  switch (truc) {
   
  case 0:
    break;
  case 1:
    Thing *str = new Thing;   
    break;
  case 2:                     
    break;
  case 3:
    break;
  }
  return 0;
}


------------   preprocessed file: (makebug.ii) -----------

# 1 "makebug.cpp"
# 1 "<interne>"
# 1 "<ligne de commande>"
# 1 "makebug.cpp"
class Thing {
public:
  Thing() {
  }
};

int main (int argc, char ** argv){

  if (argc == 1) {
    return 0;
  }

  int truc = 0;


  switch (truc) {

  case 0:
    break;
  case 1:
    Thing *th;
    th = new Thing();
    break;
  case 2:
    break;
  case 3:
    break;


  }




  switch (truc) {

  case 0:
    break;
  case 1:
    Thing *str = new Thing;
    break;
  case 2:
    break;
  case 3:
    break;
  }
  return 0;
}

-- 
           Summary: new object affectation in a switch
           Product: gcc
           Version: 3.3.6
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebmaestro at hotmail dot com
                CC: gcc-bugs at gcc dot gnu dot org,sebmaestro at hotmail
                    dot com


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


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

* [Bug c++/21487] new object affectation in a switch
  2005-05-10 12:33 [Bug c++/21487] New: new object affectation in a switch sebmaestro at hotmail dot com
@ 2005-05-10 13:12 ` pinskia at gcc dot gnu dot org
  2005-05-10 14:37 ` sebmaestro at hotmail dot com
  2005-05-10 14:51 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-10 13:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-10 13:12 -------
This is how C++ works, you can actually fall through case statements.  This is invalid code and G++ 
rejects it correctly.

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


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


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

* [Bug c++/21487] new object affectation in a switch
  2005-05-10 12:33 [Bug c++/21487] New: new object affectation in a switch sebmaestro at hotmail dot com
  2005-05-10 13:12 ` [Bug c++/21487] " pinskia at gcc dot gnu dot org
@ 2005-05-10 14:37 ` sebmaestro at hotmail dot com
  2005-05-10 14:51 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: sebmaestro at hotmail dot com @ 2005-05-10 14:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From sebmaestro at hotmail dot com  2005-05-10 14:37 -------
Subject: RE:  new object affectation in a switch

So, I don't understand why :

  switch (truc) {
  case 0:
    break;
  case 1:
    Thing *th;
    th = new Thing();
    break;
  case 2:
    break;
  case 3:
    break;
  }
is OK for g++.

  switch (truc) {
  case 0:
    break;
  case 1:
    break;
  case 2:
    break;
  case 3:
   Thing *th = new Thing;
    break;
  }

is "correct" too, but

  switch (truc) {
  case 0:
    break;
  case 1:
    Thing *th = new Thing;
    break;
  case 2:
    break;
  case 3:
    break;
  }

is rejected with a french and english (:-D) error message !





>From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
>Reply-To: gcc-bugzilla@gcc.gnu.org
>To: sebmaestro@hotmail.com
>Subject: [Bug c++/21487] new object affectation in a switch
>Date: 10 May 2005 13:12:47 -0000
>
>------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-10 
>13:12 -------
>This is how C++ works, you can actually fall through case statements.  This 
>is invalid code and G++
>rejects it correctly.
>
>--
>            What    |Removed                     |Added
>----------------------------------------------------------------------------
>              Status|UNCONFIRMED                 |RESOLVED
>          Resolution|                            |INVALID
>
>
>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21487
>
>------- You are receiving this mail because: -------
>You reported the bug, or are watching the reporter.
>You are on the CC list for the bug, or are watching someone who is.




-- 


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


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

* [Bug c++/21487] new object affectation in a switch
  2005-05-10 12:33 [Bug c++/21487] New: new object affectation in a switch sebmaestro at hotmail dot com
  2005-05-10 13:12 ` [Bug c++/21487] " pinskia at gcc dot gnu dot org
  2005-05-10 14:37 ` sebmaestro at hotmail dot com
@ 2005-05-10 14:51 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-10 14:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-10 14:51 -------
(In reply to comment #2)
> Subject: RE:  new object affectation in a switch
> 
> So, I don't understand why :
...
> is OK for g++.
Because there is no initialization of a variable in the declaration.
....
> is "correct" too, but
because there is no case statement after the initialization of the variable so there is no way to cross the 
initialization.

> is rejected with a french and english (:-D) error message !
Because you cross an initialization.

-- 


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


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

end of thread, other threads:[~2005-05-10 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-10 12:33 [Bug c++/21487] New: new object affectation in a switch sebmaestro at hotmail dot com
2005-05-10 13:12 ` [Bug c++/21487] " pinskia at gcc dot gnu dot org
2005-05-10 14:37 ` sebmaestro at hotmail dot com
2005-05-10 14:51 ` pinskia 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).