Skip to content

Commit 3a3bdd8

Browse files
authored
[clang] Fix crash when destructor definition is preceded with '=' (#90220)
Fixes #89544
1 parent 7565b20 commit 3a3bdd8

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ Bug Fixes in This Version
472472
- Clang now correctly generates overloads for bit-precise integer types for
473473
builtin operators in C++. Fixes #GH82998.
474474

475+
- Fix crash when destructor definition is preceded with an equals sign.
476+
Fixes (#GH89544).
477+
475478
- When performing mixed arithmetic between ``_Complex`` floating-point types and integers,
476479
Clang now correctly promotes the integer to its corresponding real floating-point
477480
type only rather than to the complex type (e.g. ``_Complex float / int`` is now evaluated

clang/include/clang/AST/ExprCXX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,8 @@ class CXXTemporary {
14821482
/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
14831483
/// }
14841484
/// \endcode
1485+
///
1486+
/// Destructor might be null if destructor declaration is not valid.
14851487
class CXXBindTemporaryExpr : public Expr {
14861488
CXXTemporary *Temp = nullptr;
14871489
Stmt *SubExpr = nullptr;

clang/lib/AST/Expr.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3893,9 +3893,14 @@ namespace {
38933893
}
38943894

38953895
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) {
3896-
if (E->getTemporary()->getDestructor()->isTrivial()) {
3897-
Inherited::VisitStmt(E);
3898-
return;
3896+
// Destructor of the temporary might be null if destructor declaration
3897+
// is not valid.
3898+
if (const CXXDestructorDecl *DtorDecl =
3899+
E->getTemporary()->getDestructor()) {
3900+
if (DtorDecl->isTrivial()) {
3901+
Inherited::VisitStmt(E);
3902+
return;
3903+
}
38993904
}
39003905

39013906
NonTrivial = true;

clang/test/SemaCXX/destructor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,16 @@ struct Foo : public Baz { // expected-error {{cannot override a non-deleted func
565565
};
566566
}
567567

568+
namespace GH89544 {
569+
class Foo {
570+
~Foo() = {}
571+
// expected-error@-1 {{initializer on function does not look like a pure-specifier}}
572+
// expected-error@-2 {{expected ';' at end of declaration list}}
573+
};
574+
575+
static_assert(!__is_trivially_constructible(Foo), "");
576+
static_assert(!__is_trivially_constructible(Foo, const Foo &), "");
577+
static_assert(!__is_trivially_constructible(Foo, Foo &&), "");
578+
} // namespace GH89544
579+
568580
#endif // BE_THE_HEADER

0 commit comments

Comments
 (0)