[clang] 4ca024c - [Clang] Fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (#96228)

via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 14 19:00:22 PDT 2024


Author: Oleksandr T
Date: 2024-07-15T10:00:19+08:00
New Revision: 4ca024c877e3eb20c0af518d3335883fb7b4b910

URL: https://github.com/llvm/llvm-project/commit/4ca024c877e3eb20c0af518d3335883fb7b4b910
DIFF: https://github.com/llvm/llvm-project/commit/4ca024c877e3eb20c0af518d3335883fb7b4b910.diff

LOG: [Clang] Fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (#96228)

Fixes #96043

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaDeclCXX.cpp
    clang/test/CXX/class/class.compare/class.compare.default/p1.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 35cc15142089b..83a1353f3c400 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 a7da5285ad0e4..76db539b5726b 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 252860bfc4de0..ddf82f432c2ea 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;
+}


        


More information about the cfe-commits mailing list