• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is this a known GCC bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is this a known GCC bug?


  • Subject: Re: Is this a known GCC bug?
  • From: Óscar Morales Vivó <email@hidden>
  • Date: Tue, 2 May 2006 15:39:13 -0400

Alright. I retreat in shame at not thinking about that. :\ should have known better.

On May 2, 2006, at 15:30 , Eric Albert wrote:

Unfortunately, your code is incorrect.  You're writing your switch statements like this:
switch (foo) {
case kFoo: kBar:
{
}
}
In code like this (which appears to not be legal C, but it is legal C++), kBar is not a case statement; it's a label.  The error message you reported gives you a clue to that -- gcc isn't saying that it's a duplicate case statement, but rather that it's a duplicate label.  The reason why it's a duplicate label is that you've already used the same construct with the same enums earlier in the same function, so the label was previously declared there.

Here's a simple example which makes the issue clear.  Compile this as C++ and you'll see that you don't get an error on the goto statements; instead, you get an error due to the re-use of kBar as a label.

enum {
kFoo,
kBar
};

int main(int argc, char **argv) {
switch(argc) {
case kFoo: kBar: {
goto kBar;
}
}
switch(argc) {
case kFoo: kBar: {
goto kBar;
}
}
return 0;
}

Hope this helps,
Eric

On May 2, 2006, at 11:39 AM, Óscar Morales Vivó wrote:

Filed with Bug ID# 4534072, including a small Xcode 2.2.1 sample project that shows the behavior.

Thanks in advance for your help.

On May 2, 2006, at 12:55 , Chris Espinosa wrote:

On May 2, 2006, at 8:55 AM, Óscar Morales Vivó wrote:

I'm getting spurious errors when putting more than one switch statement based on the same enumerated type in the same function (duplicate label errors that shouldn't be there to be exact).

Is that a known issue with the GCC compiler that comes with Xcode 2.2.1? The workaround is easy enough but I'd rather know if it's something that will be fixed with the next version of Xcode.

I don't find any bugs reported against this (either in Radar or in FSF's bug database).  A simple test like this compiles and executes successfully with gcc 4.0.1 in Xcode 2.2.1:

int main (int argc, char * const argv[]) {
    std::cout << "Hello, World!\n";
switch (argc) {
case a: std::cout << "No args" << std::endl; break;
case b: std::cout << "One arg" << std::endl; break;
case c: std::cout << "Two args" << std::endl; break;
}

switch (argc) {
case a: std::cout << "Still no args" << std::endl; break;
case b: std::cout << "Still one arg" << std::endl; break;
case c: std::cout << "Still two args" << std::endl; break;
}
    return 0;
}

So perhaps you are doing something different?  

Chris


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Is this a known GCC bug? (From: Óscar Morales Vivó <email@hidden>)
 >Re: Is this a known GCC bug? (From: Chris Espinosa <email@hidden>)
 >Re: Is this a known GCC bug? (From: Óscar Morales Vivó <email@hidden>)
 >Re: Is this a known GCC bug? (From: Eric Albert <email@hidden>)

  • Prev by Date: Re: Is this a known GCC bug?
  • Next by Date: Re: [Q] is there any good replacement for the Xcode?
  • Previous by thread: Re: Is this a known GCC bug?
  • Next by thread: Link error (sprintf, vsprintf missing)
  • Index(es):
    • Date
    • Thread