File tree 2 files changed +31
-2
lines changed 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -2197,6 +2197,21 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
2197
2197
// ===----------------------------------------------------------------------===//
2198
2198
2199
2199
inline bool Destroy (InterpState &S, CodePtr OpPC, uint32_t I) {
2200
+ assert (S.Current ->getFunction ());
2201
+
2202
+ // FIXME: We iterate the scope once here and then again in the destroy() call
2203
+ // below.
2204
+ for (auto &Local : S.Current ->getFunction ()->getScope (I).locals_reverse ()) {
2205
+ const Pointer &Ptr = S.Current ->getLocalPointer (Local.Offset );
2206
+
2207
+ if (Ptr .getLifetime () == Lifetime::Ended) {
2208
+ auto *D = cast<NamedDecl>(Ptr .getFieldDesc ()->asDecl ());
2209
+ S.FFDiag (D->getLocation (), diag::note_constexpr_destroy_out_of_lifetime)
2210
+ << D->getNameAsString ();
2211
+ return false ;
2212
+ }
2213
+ }
2214
+
2200
2215
S.Current ->destroy (I);
2201
2216
return true ;
2202
2217
}
Original file line number Diff line number Diff line change 1
- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter - verify=expected,both %s
2
- // RUN: %clang_cc1 -verify=ref,both %s
1
+ // RUN: %clang_cc1 -verify=expected,both -std=c++20 %s -fexperimental-new-constant-interpreter
2
+ // RUN: %clang_cc1 -verify=ref,both -std=c++20 %s
3
3
4
4
// / FIXME: Slight difference in diagnostic output here.
5
5
@@ -68,3 +68,17 @@ namespace PrimitiveMoveFn {
68
68
const float &x = y;
69
69
}
70
70
}
71
+
72
+ // / FIXME:
73
+ // / 1) This doesn't work for parameters
74
+ // / 2) We need to do this for all fields in composite scenarios
75
+ namespace PseudoDtor {
76
+ typedef int I;
77
+ constexpr bool foo () { // both-error {{never produces a constant expression}}
78
+ {
79
+ int a; // both-note {{destroying object 'a' whose lifetime has already ended}}
80
+ a.~I ();
81
+ }
82
+ return true ;
83
+ }
84
+ }
You can’t perform that action at this time.
0 commit comments