Skip to content

Commit 9d0616c

Browse files
authored
[clang][bytecode] Ignore explicit calls to trivial dtors (#112841)
This is what the current interpreter does as well.
1 parent 9698e57 commit 9d0616c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4535,6 +4535,10 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
45354535
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_delete);
45364536
}
45374537
}
4538+
// Explicit calls to trivial destructors
4539+
if (const auto *DD = dyn_cast_if_present<CXXDestructorDecl>(FuncDecl);
4540+
DD && DD->isTrivial())
4541+
return true;
45384542

45394543
QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
45404544
std::optional<PrimType> T = classify(ReturnType);

clang/test/AST/ByteCode/placement-new.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,16 @@ constexpr bool change_union_member() {
311311
return u.b == 2;
312312
}
313313
static_assert(change_union_member());
314+
315+
namespace PR48606 {
316+
struct A { mutable int n = 0; };
317+
318+
constexpr bool f() {
319+
A a;
320+
A *p = &a;
321+
p->~A();
322+
std::construct_at<A>(p);
323+
return true;
324+
}
325+
static_assert(f());
326+
}

0 commit comments

Comments
 (0)