Skip to content

[Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions #96228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}