I see from the archives this sort of question has been asked before, but none of the answers seem to address my current problem.
I have a whole load of code which involves code similar to the following test case:
long bar(void) { return 2; }
void foo(void) { goto ExitLabel; long temp = 1; long temp2 = bar(); long temp3 = 3; long temp4; ExitLabel: return; }
This always used to compile fine, but after I had to reinstall the OS (and thus the development tools as well), this code has stopped compiling. I get errors saying:
/Volumes/Development/temp/main.cpp: In function 'void foo()': /Volumes/Development/temp/main.cpp:11: error: jump to label 'ExitLabel' /Volumes/Development/temp/main.cpp:5: error: from here /Volumes/Development/temp/main.cpp:8: error: crosses initialization of 'long int temp3' /Volumes/Development/temp/main.cpp:6: error: crosses initialization of 'long int temp' /Volumes/Development/temp/main.cpp:6: warning: unused variable 'temp' /Volumes/Development/temp/main.cpp:7: warning: unused variable 'temp2' /Volumes/Development/temp/main.cpp:8: warning: unused variable 'temp3'
Notice that the compiler is NOT objecting to the initialization of temp2 or temp4, CW compiles the code fine, and GCC 4 certainly always used to compile it ok until today(!). My understanding is that (at least under C99) this is perfectly valid code as long as the variables being initialized are basic types rather than classes requiring constructors.
The command line is: CompileC build/temp.build/Debug/temp.build/Objects-normal/ppc/main.o /Volumes/Development/temp/main.cpp normal ppc c++ com.apple.compilers.gcc.4_0 cd /Volumes/Development/temp /usr/bin/gcc-4.0 -x c++ -arch ppc -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -g -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -mtune=G5 -fvisibility=hidden -fvisibility-inlines-hidden -mfix-and-continue -Wno-invalid-offsetof -mmacosx-version-min=10.4 -I/Volumes/Development/temp/build/temp.build/Debug/temp.build/temp.hmap -F/Volumes/Development/temp/build/Debug -I/Volumes/Development/temp/build/Debug/include -I/Volumes/Development/temp/build/temp.build/Debug/temp.build/DerivedSources -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c /Volumes/Development/temp/main.cpp -o /Volumes/Development/temp/build/temp.build/Debug/temp.build/Objects-normal/ppc/main.o
... and indeed "cc main.cpp" reports the same errors.
Can anyone suggest what I can do to get this to work? I would very much prefer not to have to rewrite all my existing code!
Thanks for any suggestions Jonny |