Skip to content

Commit 1be64c2

Browse files
authored
[clang][bytecode] Fix diagnostic mismatch with current interpreter (#123571)
Don't report dead pointers if we've checking for a potential constant expression.
1 parent 4b3c178 commit 1be64c2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
321321

322322
if (Ptr.isDynamic()) {
323323
S.FFDiag(Src, diag::note_constexpr_access_deleted_object) << AK;
324-
} else {
324+
} else if (!S.checkingPotentialConstantExpression()) {
325325
bool IsTemp = Ptr.isTemporary();
326326
S.FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp;
327327

clang/test/AST/ByteCode/lifetimes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ struct Foo {
77
int a;
88
};
99

10-
constexpr int dead1() { // expected-error {{never produces a constant expression}}
10+
constexpr int dead1() {
1111

1212
Foo *F2 = nullptr;
1313
{
14-
Foo F{12}; // expected-note 2{{declared here}}
14+
Foo F{12}; // expected-note {{declared here}}
1515
F2 = &F;
1616
} // Ends lifetime of F.
1717

18-
return F2->a; // expected-note 2{{read of variable whose lifetime has ended}} \
18+
return F2->a; // expected-note {{read of variable whose lifetime has ended}} \
1919
// ref-note {{read of object outside its lifetime is not allowed in a constant expression}}
2020
}
2121
static_assert(dead1() == 1, ""); // both-error {{not an integral constant expression}} \

0 commit comments

Comments
 (0)