Bug 481049 - CDT indexer not support MS-style anonymous struct
Summary: CDT indexer not support MS-style anonymous struct
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-indexer (show other bugs)
Version: 8.8.0   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:
Depends on:
Blocks:
 
Reported: 2015-10-29 14:19 EDT by wilson yu CLA
Modified: 2020-09-04 15:19 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wilson yu CLA 2015-10-29 14:19:17 EDT
Overview:

CDT indexer can't find the reference of MS-style anonymous struct's member

Steps to Reproduce:

	1) C Code:
		struct A {
			int a;
		};
		
		struct B {
			struct A;
			int b;
		};
		
		int main()
		{
			struct B b_struct;
			printf("%d",b_struct.a);
		// i m using gcc 4.5 ,show if i added the flag -fms-extensions,it can compile and run 
		// but  the CDT indexer show error : Field 'a' could not be resolved
		// is there any way to support it ?
		}

	2) If find the reference of struct A.a, CDT cannot find this line:
	printf("%d",b_struct.a);


Expected Results:

CDT indexer should find the reference of MS-style anonymous struct's member.
Comment 1 wilson yu CLA 2015-10-29 14:23:57 EDT
The original report come from Eclipse Community Forums [Sun, 21 April 2013 13:47]:
https://www.eclipse.org/forums/index.php/t/480262/

Bug I'm not sure the bug fired or not, only follow the post of Axel MuellerFriend:

  Axel MuellerFriend [Senior Member]

  You should file a bugzilla request https://bugs.eclipse.org
  This feature was added to the C11-Standard, see http://stackoverflow.com/questions/14105982/is-it-a-bad-idea-to-use-gccs-fms-extensions
Comment 2 Nathan Ridge CLA 2015-10-29 18:24:40 EDT
Thanks for the report. CDT does not currently support this Microsoft extension, but we would probably be happy to accept a patch that adds support for it.

The extension is documented at the bottom of this page:
https://msdn.microsoft.com/en-us/library/a3bbz53t.aspx
Comment 3 Christian Huettig CLA 2017-05-10 05:00:49 EDT
Any news or progress on this front?! I'm using this feature extensively (C11 std!!) and the massive red underscores and missing completion are getting annoying. :(

Thanks,
C
Comment 4 Nathan Ridge CLA 2017-05-10 11:34:33 EDT
Could someone link to some documentation or specification of this feature as standardized?
Comment 5 Christian Huettig CLA 2017-05-11 05:35:59 EDT
Unfortunately it looks costly:
https://www.iso.org/standard/57853.html

Netbeans has the same problem:
https://netbeans.org/bugzilla/show_bug.cgi?id=256329

Wikipedia says little but mentions anon struct:
https://en.wikipedia.org/wiki/C11_(C_standard_revision)

GNU GCC is more detailed about the issue:
https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html

Unfortunately what most people use still comes from the fms-extension. The following code compiles with -fms-extensions and _not_ with -std=c11:

------------------
struct A {
    int a;
    int b;
};

struct B {
    struct A;
    int c;
} b;

int main() {
    return b.a;
}

-------------------
while this compiles with gcc -std=c11:

-------------------
struct A {
    int b;
    int c;
    struct {
	int a;
    };
} b;

int main() {
    return b.a;
}
--------------------

Would be perfect if the fms-extensions would work too... Although not strictly C11.
Comment 6 Nathan Ridge CLA 2017-05-11 13:37:09 EDT
(In reply to Christian Huettig from comment #5)
> Unfortunately it looks costly:
> https://www.iso.org/standard/57853.html

There are publically available drafts that are substantially identical:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

> Wikipedia says little but mentions anon struct:
> https://en.wikipedia.org/wiki/C11_(C_standard_revision)

I believe that refers to something different - what you show in your second code example - which CDT already supports.

> GNU GCC is more detailed about the issue:
> https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html

This makes that pretty clear - your first example is a Microsoft extension, your second example is standard C11.

> Would be perfect if the fms-extensions would work too... Although not
> strictly C11.

Given that at the moment we are struggling to keep up with new standard features, like C11 and C++14, adding support for non-standard extensions is not a priority right now. However, patches are welcome as mentioned in comment 2.
Comment 7 Marv Lelgemann CLA 2018-01-15 09:20:55 EST
Any updates on this?

My project is using gnu99 standard and I can define unions with anonymous members like

struct b {
    union {
        struct a;
        struct a _base;
        ...
    };
};

but the indexer does not understand when I access b->member_of_a, but it compiles well.
Comment 8 Marv Lelgemann CLA 2018-01-15 09:22:37 EST
Sorry, not gnu99 but gnu11
Comment 9 Marv Lelgemann CLA 2018-01-15 09:23:13 EST
(In reply to Marv Lelgemann from comment #7)
> Any updates on this?
> 
> My project is using gnu99 standard and I can define unions with anonymous
> members like
> 
> struct b {
>     union {
>         struct a;
>         struct a _base;
>         ...
>     };
> };
> 
> but the indexer does not understand when I access b->member_of_a, but it
> compiles well.

I meant gnu11.