Skip to content

bool cast operator doesn't implicitly trigger #4096

Open

Description

@llvm-beanz

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

Activity

  1. added
    hlsl2021
    on Nov 22, 2021
  2. jaebaek commented on Nov 25, 2021

    @jaebaek
    Collaborator

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

  3. added
    hlsl-next
    and removed
    hlsl2021
    on Oct 4, 2022
  4. llvm-beanz commented on Feb 8, 2023

    @llvm-beanz
    CollaboratorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hlsl-next

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions