File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -721,6 +721,27 @@ bool ByteCodeExprGen<Emitter>::visitArrayInitializer(const Expr *Initializer) {
721
721
if (!this ->emitPopPtr (Initializer))
722
722
return false ;
723
723
}
724
+ return true ;
725
+ } else if (const auto *IVIE = dyn_cast<ImplicitValueInitExpr>(Initializer)) {
726
+ const ArrayType *AT = IVIE->getType ()->getAsArrayTypeUnsafe ();
727
+ assert (AT);
728
+ const auto *CAT = cast<ConstantArrayType>(AT);
729
+ size_t NumElems = CAT->getSize ().getZExtValue ();
730
+
731
+ if (Optional<PrimType> ElemT = classify (CAT->getElementType ())) {
732
+ // TODO(perf): For int and bool types, we can probably just skip this
733
+ // since we memset our Block*s to 0 and so we have the desired value
734
+ // without this.
735
+ for (size_t I = 0 ; I != NumElems; ++I) {
736
+ if (!this ->emitZero (*ElemT, Initializer))
737
+ return false ;
738
+ if (!this ->emitInitElem (*ElemT, I, Initializer))
739
+ return false ;
740
+ }
741
+ } else {
742
+ assert (false && " default initializer for non-primitive type" );
743
+ }
744
+
724
745
return true ;
725
746
}
726
747
Original file line number Diff line number Diff line change @@ -117,3 +117,15 @@ namespace indices {
117
117
// expected-error {{must be initialized by a constant expression}} \
118
118
// expected-note {{cannot refer to element -2 of array of 10}}
119
119
};
120
+
121
+ namespace DefaultInit {
122
+ template <typename T, unsigned N>
123
+ struct B {
124
+ T a[N];
125
+ };
126
+
127
+ int f () {
128
+ constexpr B<int ,10 > arr = {};
129
+ constexpr int x = arr.a [0 ];
130
+ }
131
+ };
You can’t perform that action at this time.
0 commit comments