6

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?

Kara
  • 6,115
  • 16
  • 50
  • 57
WolfgangP
  • 3,195
  • 27
  • 37

2 Answers2

3

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

Community
  • 1
  • 1
AndersK
  • 35,813
  • 6
  • 60
  • 86
  • 1
    @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 Jul 03 '10 at 00:37
  • @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. – WolfgangP Jul 03 '10 at 15:54
3

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
  • 17,280
  • 20
  • 66
  • 93
  • 1
    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 Jul 03 '10 at 00:14
  • Thanks for your hint. I reported it to Apple as well as to the gcc team. – WolfgangP Jul 03 '10 at 00:20