[BUG]: anonyous structs and unions are not added to class fields
tomazsustar opened this issue · 2 comments
tomazsustar commented
Problem description
When using the simple.py anonymous unions are not added to class fields. In my view they sould be added since they are also class embers and contribute to the object size. For each anonimous union a field with no name should be added to class fields.
Operating System
Windows
Installed Python Packages
No response
Reproducible example code
// when parsing this only member and member2 are added to example_class fields.
class example_class {
int member;
union {
std::uint32_t a;
std::uint16_t b[2];
};
int member2;
};
tomazsustar commented
I learned, that anonymous structs are not supported in C++. Anonymous unions are supported. So this bug should also be just about unions.
virtuald commented
FWIW the following code passes the compilers I tried in godbolt:
#include <cstdint>
class example_class {
int member;
struct {
int a1;
int b1;
};
union {
std::uint32_t a2;
std::uint16_t b2[2];
};
int member2;
};
It looks like anonymous structs are valid when present in a class/struct. However, the following is invalid in C++ mode but valid in C mode:
struct {
int x;
};