DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

`bool` cast operator doesn't implicitly trigger

Open llvm-beanz opened this issue 4 years ago • 1 comments

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;
}

llvm-beanz avatar Nov 22 '21 15:11 llvm-beanz

Thank you for reporting this issue. I will take a look.

jaebaek avatar Nov 25 '21 21:11 jaebaek

Pretty sure this is the cause here: https://github.com/microsoft/DirectXShaderCompiler/blob/main/tools/clang/lib/Sema/SemaOverload.cpp#L1136

I'll circle back to this issue at some point.

llvm-beanz avatar Feb 08 '23 19:02 llvm-beanz