You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error in implicit conversions when enums are involved #5807
Description
DXC seems to be having some issues when there are bit shift operations with enums. Other bit operators seem to work fine but not bit shifts. While I haven't checked the C++ spec I believe HLSL mirrors C++'s behavior. Despite that this error is not something I've seen or was able to reproduce in any of the C++ compilers that I've tested. This leads me to believe that there might be an issue with DXC.
Steps to Reproduce
Pretty simple repro case:
enum E : uint {
A,
B
};
float4 PSMain() : SV_Target0 {
uint e = E::A << 1u;
return 0.0;
}
To add a quick note. The error message here doesn't indicate it, but this is caused by HLSL's overload resolution changes. In C++ the implicit conversion sequence for an explicitly-typed enumeration that is not an enum class is the same as a non-typed enumeration (i.e. it can implicitly convert to int). In SemaHLSL.cpp under CanConvert we don't properly handle explicitly-typed non-class enumerations.
While this is a bug that we could fix in HLSL without a language change, I've also tagged this as hlsl-next because we do have plans for HLSL 202x to adopt C++ overload resolution rules in order to support global operator overloading and const instance methods. That would fix this in the next language version.
Activity
llvm-beanz commentedon Oct 3, 2023
To add a quick note. The error message here doesn't indicate it, but this is caused by HLSL's overload resolution changes. In C++ the implicit conversion sequence for an explicitly-typed enumeration that is not an enum class is the same as a non-typed enumeration (i.e. it can implicitly convert to int). In
SemaHLSL.cppunderCanConvertwe don't properly handle explicitly-typed non-class enumerations.While this is a bug that we could fix in HLSL without a language change, I've also tagged this as hlsl-next because we do have plans for HLSL 202x to adopt C++ overload resolution rules in order to support global operator overloading and
constinstance methods. That would fix this in the next language version.