[Bug c++/21487] New: new object affectation in a switch

2005-05-10 Thread sebmaestro at hotmail dot com
what follows (version, command line, source and .ii) seems to be a bug.

if you need something else -> [EMAIL PROTECTED]

"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 ""
# 1 ""
# 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


[Bug c++/21487] new object affectation in a switch

2005-05-10 Thread sebmaestro at hotmail dot com

--- 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" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>Subject: [Bug c++/21487] new object affectation in a switch
>Date: 10 May 2005 13:12:47 -
>
>--- 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