Skip to content

Commit

Permalink
[Clang] Fix cast failures by adjusting the resolution of record decla…
Browse files Browse the repository at this point in the history
…ration contexts to handle semantic and lexical distinctions (#96228)

Fixes #96043
  • Loading branch information
a-tarasyuk authored Jul 15, 2024
1 parent adaff46 commit 4ca024c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
18 changes: 18 additions & 0 deletions clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 4ca024c

Please sign in to comment.