Sizeof struct with enum value returns error
Description When using an enumerated value inside of a struct, the compiler is unable to perform a 'sizeof' on that struct member.
Steps to Reproduce Shader provided here (also will paste at the end as it's small): https://godbolt.org/z/PjsePWb6Y
Actual Behavior
Environment
- DXC version any
- Host Operating System any
RWStructuredBuffer
enum SomeEnum { SomeEnum_Val0, SomeEnum_Val1, SomeEnum_Val2, SomeEnum_Val3 };
struct SomeStruct { SomeEnum _enumMember; uint _uintMember; };
[RootSignature("UAV(u1)")] [numthreads(1, 1, 1)] void main(uint3 DTid : SV_DispatchThreadID) { g_Buffer[0] = sizeof(SomeStruct); }
When adding tests for a fix, it would be great to include a struct containing bitfield enum members as well.
I just hit this as well. It is worth noting that applying sizeof to an enum type directly also results in this error. The struct is not required. https://godbolt.org/z/6chdrWYWz
If anyone wants a workaround. You can use the fact that this generates a compiler error to construct an is_enum template... https://godbolt.org/z/K5YxsM598... and then go from there...
Turns out that if the enum appears in a base struct, then sizeof succeeds. I would recommend people start using the template in the following godbolt link (or something similar), instead of the sizeof operator. https://godbolt.org/z/b1e6rnEjh