Bug 416517 - wrong parsing of cast with inline struct definition
Summary: wrong parsing of cast with inline struct definition
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.2   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
: 390819 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-09-04 08:11 EDT by Marco Trudel CLA
Modified: 2020-09-04 15:21 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Trudel CLA 2013-09-04 08:11:20 EDT
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));
Comment 1 Nathan Ridge CLA 2013-09-05 01:52:43 EDT
(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;
           ^
Comment 2 Marco Trudel CLA 2013-09-09 06:15:47 EDT
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.
Comment 3 Nathan Ridge CLA 2013-09-13 00:14:29 EDT
(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.
Comment 4 Philipp Wendler CLA 2014-09-19 04:49:42 EDT
Any chance on getting this supported?
LLVM/clang also accepts this (I tested version 3.5).
Comment 5 Nathan Ridge CLA 2014-09-20 20:12:01 EDT
(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.
Comment 6 Nathan Ridge CLA 2015-12-29 02:16:34 EST
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.
Comment 7 Nathan Ridge CLA 2016-12-22 00:16:09 EST
*** Bug 390819 has been marked as a duplicate of this bug. ***