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) {
233
233
return false ;
234
234
}
235
235
} 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
+
236
244
if (!Ptr.isLive () && !Ptr.isTemporary ())
237
245
return false ;
238
246
Original file line number Diff line number Diff line change @@ -301,4 +301,11 @@ namespace NonConstLocal {
301
301
}
302
302
}
303
303
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
+ }
304
311
You can’t perform that action at this time.
0 commit comments