[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 12:57:12 PDT 2023


erichkeane added a comment.

As Richard says, we should just be taking the first parameter type and using that instead (obviously de-qualified and removing reference if necessary).



================
Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:964
       } else if (DFK.isComparison()) {
-        Diags.Report(Active->PointOfInstantiation,
-                     diag::note_comparison_synthesized_at)
-            << (int)DFK.asComparison()
-            << Context.getTagDeclType(
-                   cast<CXXRecordDecl>(FD->getLexicalDeclContext()));
+        CXXRecordDecl *RD = nullptr;
+        for (Decl *D : FD->redecls()) {
----------------
According to the comment on the related bug:

```
This code predates P2085R0, prior to which a comparison function could only be defaulted lexically within the class. Given that we can't use the lexically-enclosing class any more, we can instead look at the (first) parameter type to determine which class's comparison is being defaulted.
...
since the lexical context isn't the right thing for us to be looking at any more
...
```


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