| Issue |
241523
|
| Summary |
[HLSL][202x][0018] Bug in user-defined conversion functions.
|
| Labels |
HLSL
|
| Assignees |
spall
|
| Reporter |
spall
|
Current behavior:
```
struct Intensity
{
float value;
operator float() const
{
return value;
}
};
float4 main() : SV_Target
{
Intensity intensity;
intensity.value = 0.75f;
float foo = intensity; // This produces an error: error: cannot initialize a variable of type 'float' with an lvalue of type 'Intensity'
}
```
According to (https://hlsl-tc57.github.io/tc57/proposal/0018/) this should be valid.
```
User defined conversion functions will be resovled according to the rules in [0003](https://hlsl-tc57.github.io/tc57/proposal/0003/) in explicit cast expressions of the form (T)Obj and in initialization expressions for built-in types such as T X = Obj where T is a built-in type.
```
https://godbolt.org/z/jYqM5abT1
Note that this should be an error:
```
struct Intensity
{
float value;
explicit operator uint() const
{
return static_cast<uint>(value * 255.0f);
}
};
float4 main() : SV_Target
{
Intensity intensity;
intensity.value = 0.75f;
uint implicit = intensity; // should be an error because the conversion function is marked explicit.
return float4(2.0f, 1.0f, 0.0f, 1.0f);
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs