Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous struct shouldn't be named as (anonymous) #290

Closed
languagelawyer opened this issue Jan 24, 2020 · 1 comment
Closed

Anonymous struct shouldn't be named as (anonymous) #290

languagelawyer opened this issue Jan 24, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@languagelawyer
Copy link

For the code below

union U {
  struct {} s;
};

cppinsigths produces

struct U
{
  struct 
  {
  };
  
  struct (anonymous) s;
};
@andreasfertig andreasfertig added the bug Something isn't working label Jan 27, 2020
@andreasfertig
Copy link
Owner

Hello @languagelawyer,

thank you for your continuous support! That is in fact a little embarrassing, up to this point unions where not supported at all. They were shown as struct all the time.

The second thing which is wrong is the handling of anonymous structs, hence the struct (anonymous) s;. They are a bit harder to handle. In your example the resulting (down-stripped) AST is the following:

`-CXXRecordDecl 0x7fa84d82b620 <x.cpp:1:1, line:3:1> line:1:7 union U definition
  |-CXXRecordDecl 0x7fa84d82b760 <col:1, col:7> col:7 implicit union U
  |-CXXRecordDecl 0x7fa84d82b810 <line:2:3, col:11> col:3 struct definition
  `-FieldDecl 0x7fa84d82b9c0 <col:3, col:13> col:13 s 'struct (anonymous struct at x.cpp:2:3)':'U::(anonymous struct at x.cpp:2:3)'

The troublemaker is CXXRecordDecl 0x7fa84d82b810 <line:2:3, col:11> col:3 struct definition because it does not have a name. Ok it is anonymous. The FieldDecl afterwards is the declaration of s. So Clang does split the anonymous struct. Without a name it is impossible to declare the member s. My solution is to make up a name for the anonymous struct: __anon_LINE_COL_.

Andreas

andreasfertig added a commit that referenced this issue Jun 9, 2020
To this point unions where shown as a struct, as Clang internally models
them as a CXXRecordDecl.

Also unsupported where anonymous structs. Due to the declaration order
in Clang a name based on line/column prefixed with `__anon_` is made up
to be able to refer to the struct later in a `FieldDecl`.
andreasfertig added a commit that referenced this issue Jun 9, 2020
To this point unions where shown as a struct, as Clang internally models
them as a CXXRecordDecl.

Also unsupported where anonymous structs. Due to the declaration order
in Clang a name based on line/column prefixed with `__anon_` is made up
to be able to refer to the struct later in a `FieldDecl`.
andreasfertig added a commit that referenced this issue Jun 9, 2020
Fixed #290: Added support for unions and anonymous structs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants