File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -233,6 +233,14 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
233233 return false ;
234234 }
235235 } else {
236+ // If this is pointing to a local variable, just return
237+ // the result, even if the pointer is dead.
238+ // This will later be diagnosed by CheckLValueConstantExpression.
239+ if (Ptr.isBlockPointer () && !Ptr.block ()->isStatic ()) {
240+ EvalResult.setValue (Ptr.toAPValue (Ctx.getASTContext ()));
241+ return true ;
242+ }
243+
236244 if (!Ptr.isLive () && !Ptr.isTemporary ())
237245 return false ;
238246
Original file line number Diff line number Diff line change @@ -301,4 +301,11 @@ namespace NonConstLocal {
301301 }
302302}
303303
304+ #define ATTR __attribute__ ((require_constant_initialization))
305+ int somefunc() {
306+ const int non_global = 42 ; // both-note {{declared here}}
307+ ATTR static const int &local_init = non_global; // both-error {{variable does not have a constant initializer}} \
308+ // both-note {{required by}} \
309+ // both-note {{reference to 'non_global' is not a constant expression}}
310+ }
304311
You can’t perform that action at this time.
0 commit comments