File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -3239,9 +3239,14 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
3239
3239
return this ->emitGetPtrThisField (Offset, E);
3240
3240
}
3241
3241
3242
- // Lazily visit global declarations we haven't seen yet.
3243
- // This happens in C.
3244
- if (!Ctx.getLangOpts ().CPlusPlus ) {
3242
+ // Try to lazily visit (or emit dummy pointers for) declarations
3243
+ // we haven't seen yet.
3244
+ if (Ctx.getLangOpts ().CPlusPlus ) {
3245
+ if (const auto *VD = dyn_cast<VarDecl>(D); VD && VD->isStaticLocal ()) {
3246
+ if (std::optional<unsigned > I = P.getOrCreateDummy (D))
3247
+ return this ->emitGetPtrGlobal (*I, E);
3248
+ }
3249
+ } else {
3245
3250
if (const auto *VD = dyn_cast<VarDecl>(D);
3246
3251
VD && VD->getAnyInitializer () && VD->getType ().isConstQualified ()) {
3247
3252
if (!this ->visitVarDecl (VD))
Original file line number Diff line number Diff line change @@ -523,3 +523,23 @@ namespace Move {
523
523
constexpr int A = std::move(5 );
524
524
static_assert (A == 5 , " " );
525
525
}
526
+
527
+ namespace StaticLocals {
528
+ void test () {
529
+ static int j; // both-note {{declared here}}
530
+ static_assert (&j != nullptr , " " ); // both-warning {{always true}}
531
+
532
+ static_assert (j == 0 , " " ); // both-error {{not an integral constant expression}} \
533
+ // both-note {{read of non-const variable 'j'}}
534
+
535
+ static int k = 0 ; // both-note {{declared here}}
536
+ static_assert (k == 0 , " " ); // both-error {{not an integral constant expression}} \
537
+ // both-note {{read of non-const variable 'k'}}
538
+
539
+ static const int l = 12 ;
540
+ static_assert (l == 12 , " " );
541
+
542
+ static const int m; // both-error {{default initialization}}
543
+ static_assert (m == 0 , " " );
544
+ }
545
+ }
You can’t perform that action at this time.
0 commit comments