[PATCH] D151365: [Sema] cast to CXXRecordDecl correctly when diag a default comparison method

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 13:12:26 PDT 2023


erichkeane added a comment.

In D151365#4369650 <https://reviews.llvm.org/D151365#4369650>, @HerrCai0907 wrote:

> In D151365#4369605 <https://reviews.llvm.org/D151365#4369605>, @erichkeane wrote:
>
>> As Richard says, we should just be taking the first parameter type and using that instead (obviously de-qualified and removing reference if necessary).
>
> But we still can find the correct RecordDecl by `redecls`.

That ends up being an absurdly larger amount of work, and in the case of a 'friend' declaration can result in the wrong answer, correct?  Consider something like:

  struct Foo;
  
  struct Bar {
      friend bool operator==(const Foo&, const Foo&);
  };
  
  struct Foo {
      friend bool operator==(const Foo&, const Foo&);
  };
  
  bool operator==(const Foo&, const Foo&) = default;

or even:

  struct Foo {
      bool operator==(const Foo&) const;
  };
  
  struct Bar {
      friend bool Foo::operator==(const Foo&) const;
  };
  
  
  bool operator==(Foo, Foo) = default;

In the 1st one, the lexical context could be 'Bar'.  Searching 'redecls' will end up with the 'first one first', so at least the 2nd example isn't as problematic, but I'm sure someone more clever than I could come up with a case where that could be declared in a different order.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151365/new/

https://reviews.llvm.org/D151365



More information about the cfe-commits mailing list