Skip to content

Commit 96336ac

Browse files
authored
[clang][bytecode] Tighten double-destroy check (#129528)
The instance pointer of the current function being the same as the one we're destroying is only relevant if said function is also a destructor.
1 parent d37a392 commit 96336ac

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,8 @@ static bool runRecordDestructor(InterpState &S, CodePtr OpPC,
992992
const Record *R = Desc->ElemRecord;
993993
assert(R);
994994

995-
if (Pointer::pointToSameBlock(BasePtr, S.Current->getThis())) {
995+
if (Pointer::pointToSameBlock(BasePtr, S.Current->getThis()) &&
996+
S.Current->getFunction()->isDestructor()) {
996997
const SourceInfo &Loc = S.Current->getSource(OpPC);
997998
S.FFDiag(Loc, diag::note_constexpr_double_destroy);
998999
return false;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ namespace DeleteThis {
558558
}
559559
static_assert(super_secret_double_delete()); // both-error {{not an integral constant expression}} \
560560
// both-note {{in call to 'super_secret_double_delete()'}}
561+
562+
struct B {
563+
constexpr void reset() { delete this; }
564+
};
565+
static_assert(((new B)->reset(), true));
561566
}
562567

563568
namespace CastedDelete {

0 commit comments

Comments
 (0)