[clang] [clang] Fix crash when destructor definition is preceded with '=' (PR #90220)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 26 08:24:03 PDT 2024
================
@@ -3893,9 +3893,12 @@ namespace {
}
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) {
- if (E->getTemporary()->getDestructor()->isTrivial()) {
- Inherited::VisitStmt(E);
- return;
+ if (const CXXDestructorDecl *DtorDecl =
+ E->getTemporary()->getDestructor()) {
+ if (DtorDecl->isTrivial()) {
+ Inherited::VisitStmt(E);
+ return;
+ }
----------------
Sirraide wrote:
As you already pointed out, this does seem like a weird fix for this. I’m not sure this is right. The documentation for `CXXBindTemporaryExpr` states:
```
/// This ensures the destructor is called for the temporary. It should only be
/// needed for non-POD, non-trivially destructable class types.
```
To me at least, this sounds like we should never get here with the destructor being null. Perhaps another approach would be to simply ignore the `=` if the next token is `{` and parse a function body.
If the next token is not `{`, then we could ignore everything following it up to the next semicolon (unless it’s `= delete`, `= default`, or `= 0`, of course), i.e. essentially treat it as though it were `~Foo();`—if that’s not too complicated. And if we’re going with that, `assert`ing that the destructor is never null here is probably a good idea.
https://github.com/llvm/llvm-project/pull/90220
More information about the cfe-commits
mailing list