views:

64

answers:

2

Compiling this code

int main(int argc, char **argv)
{
    int xor = 0;
}

via

g++ main.cpp 

results in:

internal compiler error: Segmentation fault

with

i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5659).

Renaming the variable removes the error.

Question: Is gcc from Apple crap?

+2  A: 

and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor and xor_eq are keywords which are enabled with -ansi or -foperator-names

you have one of those switches enabled?

check also out: this

Anders K.
Thanks for pointing out this 'hidden feature'!
Wolfgang Plaschg
@Wolfgang, it's not really g++-specific, or hidden. The C++ standard says `xor` is reserved, and using a reserved word in another context is undefined behavior. That means anything can happen. Of course, it's preferable for the compiler to print a clear error message.
Matthew Flaschen
@Matthew I meant it as a joke. To use logical operators spelled out in conditions is quite a nice feature which makes code more readable (esp. to collegues who are used to scripting languages), but i doubt that many C++ programmers know about or use this.
Wolfgang Plaschg
+1  A: 

Any time your compiler segfaults, it's a bug. Your already reduced test case is a perfect candidate to be reported to GCC.

Clark Gaebel
It should be reported to Apple (http://developer.apple.com/bugreporter/). They can best determine if it's a bug they introduced, or present in upstream. If it is in upstream, they will typically file a bug there.
Matthew Flaschen
Thanks for your hint. I reported it to Apple as well as to the gcc team.
Wolfgang Plaschg