File tree Expand file tree Collapse file tree 2 files changed +6
-22
lines changed Expand file tree Collapse file tree 2 files changed +6
-22
lines changed Original file line number Diff line number Diff line change @@ -318,18 +318,6 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
318
318
bool Ret (InterpState &S, CodePtr &PC) {
319
319
const T &Ret = S.Stk .pop <T>();
320
320
321
- // Make sure returned pointers are live. We might be trying to return a
322
- // pointer or reference to a local variable.
323
- // Just return false, since a diagnostic has already been emitted in Sema.
324
- if constexpr (std::is_same_v<T, Pointer>) {
325
- // FIXME: We could be calling isLive() here, but the emitted diagnostics
326
- // seem a little weird, at least if the returned expression is of
327
- // pointer type.
328
- // Null pointers are considered live here.
329
- if (!Ret.isZero () && !Ret.isLive ())
330
- return false ;
331
- }
332
-
333
321
assert (S.Current );
334
322
assert (S.Current ->getFrameOffset () == S.Stk .size () && " Invalid frame" );
335
323
if (!S.checkingPotentialConstantExpression () || S.Current ->Caller )
Original file line number Diff line number Diff line change @@ -303,21 +303,17 @@ namespace ReturnLocalPtr {
303
303
return &a; // both-warning {{address of stack memory}}
304
304
}
305
305
306
- // / GCC rejects the expression below, just like the new interpreter. The current interpreter
307
- // / however accepts it and only warns about the function above returning an address to stack
308
- // / memory. If we change the condition to 'p() != nullptr', it even succeeds.
309
- static_assert (p() == nullptr , " " ); // ref-error {{static assertion failed}} \
310
- // expected-error {{not an integral constant expression}}
311
-
312
- // / FIXME: The current interpreter emits diagnostics in the reference case below, but the
313
- // / new one does not.
306
+ // / FIXME: Both interpreters should diagnose this. We're returning a pointer to a local
307
+ // / variable.
308
+ static_assert (p() == nullptr , " " ); // both-error {{static assertion failed}}
309
+
314
310
constexpr const int &p2 () {
315
- int a = 12 ; // ref -note {{declared here}}
311
+ int a = 12 ; // both -note {{declared here}}
316
312
return a; // both-warning {{reference to stack memory associated with local variable}}
317
313
}
318
314
319
315
static_assert (p2() == 12 , " " ); // both-error {{not an integral constant expression}} \
320
- // ref -note {{read of variable whose lifetime has ended}}
316
+ // both -note {{read of variable whose lifetime has ended}}
321
317
}
322
318
323
319
namespace VoidReturn {
You can’t perform that action at this time.
0 commit comments