Community
Participate
Working Groups
This code works fine with GCC but CDT can't parse it: int main() { (struct { int a; int b; } *)0; return 0; } CDT errors: - Syntax error in file: test.c:2 -> (struct { int a; int b; } - Syntax error in file: test.c:2 -> *)0; This comes from an offsetof macro: offsetof(struct { int a; int b; }, b));
(In reply to Missing name from comment #0) > This code works fine with GCC but CDT can't parse it: > int main() { > (struct { int a; int b; } *)0; > return 0; > } What GCC version are you using that accepts this? With GCC 4.8, I get: test.cpp: In function 'int main()': test.cpp:140:11: error: types may not be defined in casts (struct { int a; int b; } *)0; ^
I compiled this code in the last 4 years on multiple systems with various GCC versions. Currently this works with: - gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3 - gcc.exe (GCC) 4.4.5 20100710 (prerelease) [svn/rev.162041 - mingw-w64/oz] So I would assume that this was supported up to GCC 4.8.
(In reply to Missing name from comment #2) > I compiled this code in the last 4 years on multiple systems with various > GCC versions. Currently this works with: > - gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3 > - gcc.exe (GCC) 4.4.5 20100710 (prerelease) [svn/rev.162041 - mingw-w64/oz] > > So I would assume that this was supported up to GCC 4.8. It looks like this is allowed in C but not C++ (I was trying it with C++, hence the error). Version of gcc does not matter.
Any chance on getting this supported? LLVM/clang also accepts this (I tested version 3.5).
(In reply to Philipp Wendler from comment #4) > Any chance on getting this supported? I personally have no plans to work on C-specific features in the short term. However, I'd be happy to review a patch if someone writes one.
It appears that my changes in bug 472950 (shipped in CDT 8.8) caused us to start accepting this in both C and C++ mode. That wasn't my intention, but given that we want to accept it in C mode, it's an improvement. I'm going to keep this bug open for changing the C++ parser to _not_ accept it, so that we remain consistent with GCC.
*** Bug 390819 has been marked as a duplicate of this bug. ***