Skip to content

Commit ee57ce5

Browse files
authored
[Clang] prevent checking destructor reference with an invalid initializer (#97860)
Fixes #97230
1 parent b66310f commit ee57ce5

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Bug Fixes to C++ Support
163163

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

167168
Bug Fixes to AST Handling
168169
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaInit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,9 @@ static bool checkDestructorReference(QualType ElementType, SourceLocation Loc,
19861986
return false;
19871987

19881988
CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
1989+
if (!Destructor)
1990+
return false;
1991+
19891992
SemaRef.CheckDestructorAccess(Loc, Destructor,
19901993
SemaRef.PDiag(diag::err_access_dtor_temp)
19911994
<< ElementType);

clang/test/SemaCXX/destructor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,13 @@ static_assert(!__is_trivially_constructible(Foo, const Foo &), "");
577577
static_assert(!__is_trivially_constructible(Foo, Foo &&), "");
578578
} // namespace GH89544
579579

580+
namespace GH97230 {
581+
struct X {
582+
~X() = defaul; // expected-error {{initializer on function does not look like a pure-specifier}} \
583+
// expected-error {{use of undeclared identifier 'defaul'}}
584+
};
585+
struct Y : X {} y1{ }; // expected-error {{call to implicitly-deleted default constructor of 'struct Y'}} \
586+
// expected-note {{default constructor of 'Y' is implicitly deleted because base class 'X' has no destructor}}
587+
}
588+
580589
#endif // BE_THE_HEADER

0 commit comments

Comments
 (0)