Skip to content
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

[Clang] prevent checking destructor reference with an invalid initializer #97860

Merged
merged 14 commits into from
Jul 29, 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 @@ -151,6 +151,7 @@ Bug Fixes to C++ Support

- Fixed a crash when an expression with a dependent ``__typeof__`` type is used as the operand of a unary operator. (#GH97646)
- Fixed a failed assertion when checking invalid delete operator declaration. (#GH96191)
- Fix a crash when checking destructor reference with an invalid initializer. (#GH97230)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,9 @@ static bool checkDestructorReference(QualType ElementType, SourceLocation Loc,
return false;

CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
if (!Destructor)
return false;

SemaRef.CheckDestructorAccess(Loc, Destructor,
SemaRef.PDiag(diag::err_access_dtor_temp)
<< ElementType);
Expand Down
9 changes: 9 additions & 0 deletions clang/test/SemaCXX/destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,4 +577,13 @@ static_assert(!__is_trivially_constructible(Foo, const Foo &), "");
static_assert(!__is_trivially_constructible(Foo, Foo &&), "");
} // namespace GH89544

namespace GH97230 {
struct X {
~X() = defaul; // expected-error {{initializer on function does not look like a pure-specifier}} \
// expected-error {{use of undeclared identifier 'defaul'}}
};
struct Y : X {} y1{ }; // expected-error {{call to implicitly-deleted default constructor of 'struct Y'}} \
// expected-note {{default constructor of 'Y' is implicitly deleted because base class 'X' has no destructor}}
}

#endif // BE_THE_HEADER