Skip to content

Add parens when implicitly calling conversion operator after dereference #724

Description

@Ukilele

Following code

struct Foo {
  operator int() { return 1; }
};

int main() {
  Foo f;
  Foo* p = &f;
  int i = *p;
}

gets transformed to

struct Foo
{
  inline operator int ()
  {
    return 1;
  }
  
  // inline constexpr Foo() noexcept = default;
};


int main()
{
  Foo f;
  Foo * p = &f;
  int i = *p.operator int();
  return 0;
}

The resulting line that looks suspicious to me, is: int i = *p.operator int();. According to the C++ operator precedence, the . comes before *. But in our sample, we want to execute the * before the .. So I guess the resulting line should be int i = (*p).operator int();. Right?

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions