Skip to content

Commit c982465

Browse files
committed
[Clang] use parent declaration context to avoid asserting cast failure in defaulted comparison method
1 parent ace069d commit c982465

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ Bug Fixes to C++ Support
889889
between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (#GH95366).
890890
- Fix immediate escalation bugs in the presence of dependent call arguments. (#GH94935)
891891
- Clang now diagnoses explicit specializations with storage class specifiers in all contexts.
892-
892+
- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043).
893893

894894
Bug Fixes to AST Handling
895895
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9192,7 +9192,7 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc,
91929192
EnterExpressionEvaluationContext Context(
91939193
S, Sema::ExpressionEvaluationContext::Unevaluated);
91949194

9195-
CXXRecordDecl *RD = cast<CXXRecordDecl>(FD->getLexicalParent());
9195+
CXXRecordDecl *RD = cast<CXXRecordDecl>(FD->getDeclContext());
91969196
SourceLocation BodyLoc =
91979197
FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation();
91989198
StmtResult Body =
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
template <typename> class a {};
5+
template <typename b> b c(a<b>);
6+
template <typename d> class e {
7+
public:
8+
typedef a<d *> f;
9+
f begin();
10+
};
11+
template <typename d, typename g> constexpr bool operator==(d h, g i) {
12+
return *c(h.begin()) == *c(i.begin());
13+
}
14+
struct j {
15+
e<j> bar;
16+
bool operator==(const j &) const;
17+
};
18+
bool j::operator==(const j &) const = default;

0 commit comments

Comments
 (0)