Skip to content

[clang] Fix crash when destructor definition is preceded with '=' #90220

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 4 commits into from
May 1, 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
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ Bug Fixes in This Version
- Clang now correctly generates overloads for bit-precise integer types for
builtin operators in C++. Fixes #GH82998.

- Fix crash when destructor definition is preceded with an equals sign.
Fixes (#GH89544).

- When performing mixed arithmetic between ``_Complex`` floating-point types and integers,
Clang now correctly promotes the integer to its corresponding real floating-point
type only rather than to the complex type (e.g. ``_Complex float / int`` is now evaluated
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,8 @@ class CXXTemporary {
/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
/// }
/// \endcode
///
/// Destructor might be null if destructor declaration is not valid.
class CXXBindTemporaryExpr : public Expr {
CXXTemporary *Temp = nullptr;
Stmt *SubExpr = nullptr;
Expand Down
11 changes: 8 additions & 3 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3893,9 +3893,14 @@ namespace {
}

void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) {
if (E->getTemporary()->getDestructor()->isTrivial()) {
Inherited::VisitStmt(E);
return;
// Destructor of the temporary might be null if destructor declaration
// is not valid.
if (const CXXDestructorDecl *DtorDecl =
E->getTemporary()->getDestructor()) {
if (DtorDecl->isTrivial()) {
Inherited::VisitStmt(E);
return;
}
}

NonTrivial = true;
Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaCXX/destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,16 @@ struct Foo : public Baz { // expected-error {{cannot override a non-deleted func
};
}

namespace GH89544 {
class Foo {
~Foo() = {}
// expected-error@-1 {{initializer on function does not look like a pure-specifier}}
// expected-error@-2 {{expected ';' at end of declaration list}}
};

static_assert(!__is_trivially_constructible(Foo), "");
static_assert(!__is_trivially_constructible(Foo, const Foo &), "");
static_assert(!__is_trivially_constructible(Foo, Foo &&), "");
} // namespace GH89544

#endif // BE_THE_HEADER