microsoft / microsoft/DirectXShaderCompiler
`bool` cast operator doesn't implicitly trigger
Open
Nobody has claimed this yet.
hlsl-next
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
If a struct has a defined cast operator for bool, the expected behavior would be that the struct can be used in if statements and cast to bool implicitly. This currently does not work in the following example.
struct Foo {
int x;
operator bool() {
return x < 5;
}
};
[numthreads(1, 1, 1)]
void main(uint tidx : SV_DispatchThreadId) {
Foo A = {1};
if (A)
A.x += 2;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the HLSL reproducer in the issue and trace how the compiler handles a user-defined operator bool in an if statement and an implicit bool conversion. Done means the example compiles and the conditional uses Foo's conversion as described, with regression coverage for this behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100