Skip to content

Commit 4ca024c

Browse files
authored
[Clang] Fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (#96228)
Fixes #96043
1 parent adaff46 commit 4ca024c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ Bug Fixes to C++ Support
10411041
(#GH48937)
10421042
- Fix a crash when parsing an invalid type-requirement in a requires expression. (#GH51868)
10431043
- Fix parsing of built-in type-traits such as ``__is_pointer`` in libstdc++ headers. (#GH95598)
1044+
- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043).
10441045

10451046
Bug Fixes to AST Handling
10461047
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9070,7 +9070,10 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc,
90709070
EnterExpressionEvaluationContext Context(
90719071
S, Sema::ExpressionEvaluationContext::Unevaluated);
90729072

9073-
CXXRecordDecl *RD = cast<CXXRecordDecl>(FD->getLexicalParent());
9073+
CXXRecordDecl *RD =
9074+
cast<CXXRecordDecl>(FD->getFriendObjectKind() == Decl::FOK_None
9075+
? FD->getDeclContext()
9076+
: FD->getLexicalDeclContext());
90749077
SourceLocation BodyLoc =
90759078
FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation();
90769079
StmtResult Body =

clang/test/CXX/class/class.compare/class.compare.default/p1.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,21 @@ void f2() {
265265
// access info for unnamed bit-field
266266
}
267267
}
268+
269+
namespace GH96043 {
270+
template <typename> class a {};
271+
template <typename b> b c(a<b>);
272+
template <typename d> class e {
273+
public:
274+
typedef a<d *> f;
275+
f begin();
276+
};
277+
template <typename d, typename g> constexpr bool operator==(d h, g i) {
278+
return *c(h.begin()) == *c(i.begin());
279+
}
280+
struct j {
281+
e<j> bar;
282+
bool operator==(const j &) const;
283+
};
284+
bool j::operator==(const j &) const = default;
285+
}

0 commit comments

Comments
 (0)