diff options
author | Oleksandr T <oleksandr.tarasiuk@outlook.com> | 2024-07-15 05:00:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 10:00:19 +0800 |
commit | 4ca024c877e3eb20c0af518d3335883fb7b4b910 (patch) | |
tree | ad8fff9a4a87c9eb681d5a18c08cd85131a195ba | |
parent | adaff46d087799072438dd744b038e6fd50a2d78 (diff) | |
download | llvm-4ca024c877e3eb20c0af518d3335883fb7b4b910.zip llvm-4ca024c877e3eb20c0af518d3335883fb7b4b910.tar.gz llvm-4ca024c877e3eb20c0af518d3335883fb7b4b910.tar.bz2 |
[Clang] Fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (#96228)
Fixes #96043
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 1 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 5 | ||||
-rw-r--r-- | clang/test/CXX/class/class.compare/class.compare.default/p1.cpp | 18 |
3 files changed, 23 insertions, 1 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 35cc151..83a1353 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1041,6 +1041,7 @@ Bug Fixes to C++ Support (#GH48937) - Fix a crash when parsing an invalid type-requirement in a requires expression. (#GH51868) - Fix parsing of built-in type-traits such as ``__is_pointer`` in libstdc++ headers. (#GH95598) +- 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 a7da528..76db539 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9070,7 +9070,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 252860b..ddf82f4 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; +} |