https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/96228
>From 9e2730da07df0ee5102912490a687ba40bf06def Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Mon, 24 Jun 2024 18:55:51 +0300 Subject: [PATCH] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDeclCXX.cpp | 5 ++++- .../class.compare/class.compare.default/p1.cpp | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index df579ae398c5ef..86bd8cf4a6210b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -934,6 +934,7 @@ Bug Fixes to C++ Support - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). +- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043). Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 9b220103247dd0..0ecad756d44999 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9192,7 +9192,10 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); - CXXRecordDecl *RD = cast<CXXRecordDecl>(FD->getLexicalParent()); + CXXRecordDecl *RD = + cast<CXXRecordDecl>(FD->getFriendObjectKind() == Decl::FOK_None + ? FD->getDeclContext() + : FD->getLexicalDeclContext()); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp index 252860bfc4de07..ddf82f432c2eab 100644 --- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp +++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp @@ -265,3 +265,21 @@ void f2() { // access info for unnamed bit-field } } + +namespace GH96043 { +template <typename> class a {}; +template <typename b> b c(a<b>); +template <typename d> class e { +public: + typedef a<d *> f; + f begin(); +}; +template <typename d, typename g> constexpr bool operator==(d h, g i) { + return *c(h.begin()) == *c(i.begin()); +} +struct j { + e<j> bar; + bool operator==(const j &) const; +}; +bool j::operator==(const j &) const = default; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits