Hello, I would like to report about two (probably, self-connected) bugs in the __typeof__ C function. These bugs are reproduced when I am trying to compile a simple code with XLC compiler on AIX 5.2. Please, look at the code snippets below.
1. typeof_example_1.c long Func(int x) { return x; } int main() { int y, z = 1; y = (__typeof__(Func(z)))0; return 0; } cc_r typeof_example_1.c "typeof_example_1.c", line 5.26: 1506-045 (S) Undeclared identifier z. The 'z' variable is obviously defined, so "Undeclared identifier" message is wrong. 2. typeof_example_2.c (fails on 64bit compilation only) long Func(int x) { return x; } int main() { int y, z = 1; y = (__typeof__(Func((__typeof__(z))z)))0; return 0; } cc_r -q64 typeof_example_2.c "typeof_example_2.c", line 5.21: 1506-343 (S) Redeclaration of Func differs from previous declaration on line 1 of "typeof_example_2.c". "typeof_example_2.c", line 5.21: 1506-050 (I) Return type "int" in redeclaration is not compatible with the previous return type "long". Here the compiler erroneously considers the line as a function declaration, but is is a call and not a declaration. This works although for 32bit compilation. Both code snippets work with GCC compiler in both 32-bit and 64bit modes. What is interesting, we use cc_r, but not xlc binary in our build system (it is probably due to historical reasons and persons who can answer me why exactly cc_r have gone many years ago). But with xlc both code snippets also fail, however with other error messages (no matter, 32 or 64bit). xlc typeof_example_1.c "typeof_example_1.c", line 5.30: 1506-275 (S) Unexpected text integer constant encountered. xlc typeof_example_2.c "typeof_example_2.c", line 5.41: 1506-275 (S) Unexpected text z encountered. "typeof_example_2.c", line 5.45: 1506-275 (S) Unexpected text integer constant encountered. Environment: uname -a AIX pavo 2 5 00C9E74E4C00 which cc_r /usr/vac/bin/cc_r which xlc /usr/vac/bin/xlc ls /usr/vac/bin/ CreateExportList cc128 cc_r4 cleanpdf xlc128 xlc_r4 c89 cc128_r cc_r7 resetpdf xlc128_r xlc_r7 cc cc_r cforaixhelp xlc xlc_r Use case: These issues were discovered at attempt to build FreeType 2.7.0 with XLC compiler. The link to the FreeType issue: http://savannah.nongnu.org/bugs/?49448. I have contacted FreeType developers and got a feedback that TYPEOF implementation is taken from gnulib's intprops.h, that is why my question is addressed to gnu.org mail list. I do understand that the OS AIX 5.2 is legacy and the best way is to migrate to a newer one, but we cannot do it right now because customers request builds for this OS. I would be happy if you could give some clue why __typeof__ works completely differently for XLC. Thanks in advance! -- Best Regards, Alexander Samoilov, Build & Integration Ingenieur, Compart AG (Böblingen, Germany)