diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index cb0ce886f6680..4b26cc66cd09a 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -321,7 +321,7 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr, if (Ptr.isDynamic()) { S.FFDiag(Src, diag::note_constexpr_access_deleted_object) << AK; - } else { + } else if (!S.checkingPotentialConstantExpression()) { bool IsTemp = Ptr.isTemporary(); S.FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp; diff --git a/clang/test/AST/ByteCode/lifetimes.cpp b/clang/test/AST/ByteCode/lifetimes.cpp index 9a99485c4a40b..43039d0c766e9 100644 --- a/clang/test/AST/ByteCode/lifetimes.cpp +++ b/clang/test/AST/ByteCode/lifetimes.cpp @@ -7,15 +7,15 @@ struct Foo { int a; }; -constexpr int dead1() { // expected-error {{never produces a constant expression}} +constexpr int dead1() { Foo *F2 = nullptr; { - Foo F{12}; // expected-note 2{{declared here}} + Foo F{12}; // expected-note {{declared here}} F2 = &F; } // Ends lifetime of F. - return F2->a; // expected-note 2{{read of variable whose lifetime has ended}} \ + return F2->a; // expected-note {{read of variable whose lifetime has ended}} \ // ref-note {{read of object outside its lifetime is not allowed in a constant expression}} } static_assert(dead1() == 1, ""); // both-error {{not an integral constant expression}} \