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
Should emit error on unsupported cast operator overloading that's silently ignored #5103
The cast operator syntax was enabled for HLSL 2021, but it is not really supported by the compiler. We silently ignore cast operators and perform casting as we would have without the operator. That is, we allow C-style casting of aggregate types to another type of fewer or equal components.
We should emit an error when someone tries to define a cast operator, so people are not misled that it works, since it's easy to be fooled, when it didn't do what you expected it to do.
struct MyStruct {
float4 f;
// We should emit an error that we don't support cast operator overloading:
operator float4() {
return42;
}
};
MyStruct foo;
float4main() : OUT {
// This compiles and merely casts the contents of foo to float4,// instead of calling the float4() operator and returning 42.return (float4)foo;
}
I think you are misunderstanding what you're seeing there. DXC explicitly does not resolve overloads in those expressions. Instead it interprets the expression as it is written which is as a flat-conversion cast:
Activity
tex3d commentedon Mar 17, 2023
Related to #4096.
llvm-beanz commentedon Mar 23, 2023
We don't handle it in overload resolution, but we do support them in some contexts when we can resolve them correctly:
https://godbolt.org/z/GvsqcnKnY
devshgraphicsprogramming commentedon May 17, 2024
you resolve them and yet I can't see any side effects of calling things inside a conversion operator
https://godbolt.org/z/31fPhq743 (SPIR-V)
https://godbolt.org/z/GGEzsr3E5 (DXIL)
llvm-beanz commentedon May 17, 2024
I think you are misunderstanding what you're seeing there. DXC explicitly does not resolve overloads in those expressions. Instead it interprets the expression as it is written which is as a flat-conversion cast:
Compiler Explorer
This is a known bug in DXC where overload resolution only occurs for function calls and a subset of expressions.
Emit error for user-defined conversion operators in HLSL (fixes micro…
Emit an error when attempting add a user-defined conversion function (m…