File tree Expand file tree Collapse file tree 2 files changed +43
-10
lines changed Expand file tree Collapse file tree 2 files changed +43
-10
lines changed Original file line number Diff line number Diff line change @@ -672,18 +672,28 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
672
672
}
673
673
674
674
if (T->isAnyComplexType ()) {
675
- unsigned InitIndex = 0 ;
676
- for (const Expr *Init : E->inits ()) {
677
- PrimType InitT = classifyPrim (Init->getType ());
678
-
679
- if (!this ->visit (Init))
680
- return false ;
675
+ unsigned NumInits = E->getNumInits ();
676
+ QualType ElemQT = E->getType ()->getAs <ComplexType>()->getElementType ();
677
+ PrimType ElemT = classifyPrim (ElemQT);
678
+ if (NumInits == 0 ) {
679
+ // Zero-initialize both elements.
680
+ for (unsigned I = 0 ; I < 2 ; ++I) {
681
+ if (!this ->visitZeroInitializer (ElemT, ElemQT, E))
682
+ return false ;
683
+ if (!this ->emitInitElem (ElemT, I, E))
684
+ return false ;
685
+ }
686
+ } else if (NumInits == 2 ) {
687
+ unsigned InitIndex = 0 ;
688
+ for (const Expr *Init : E->inits ()) {
689
+ if (!this ->visit (Init))
690
+ return false ;
681
691
682
- if (!this ->emitInitElem (InitT, InitIndex, E))
683
- return false ;
684
- ++InitIndex;
692
+ if (!this ->emitInitElem (ElemT, InitIndex, E))
693
+ return false ;
694
+ ++InitIndex;
695
+ }
685
696
}
686
- assert (InitIndex == 2 );
687
697
return true ;
688
698
}
689
699
Original file line number Diff line number Diff line change @@ -29,5 +29,28 @@ static_assert(__real(I1) == 1, "");
29
29
static_assert (__imag(I1) == 2, "");
30
30
31
31
32
+ constexpr _Complex double D1 = {};
33
+ static_assert (__real(D1) == 0, "");
34
+ static_assert (__imag(D1) == 0, "");
35
+
36
+ constexpr _Complex int I2 = {};
37
+ static_assert (__real(I2) == 0, "");
38
+ static_assert (__imag(I2) == 0, "");
39
+
40
+
41
+ #if 0
42
+ /// FIXME: This should work in the new interpreter.
43
+ constexpr _Complex double D2 = {12};
44
+ static_assert(__real(D2) == 12, "");
45
+ static_assert(__imag(D2) == 12, "");
46
+
47
+ constexpr _Complex int I3 = {15};
48
+ static_assert(__real(I3) == 15, "");
49
+ static_assert(__imag(I3) == 15, "");
50
+ #endif
51
+
52
+
53
+
54
+
32
55
// / FIXME: This should work in the new interpreter as well.
33
56
// constexpr _Complex _BitInt(8) A = 0;// = {4};
You can’t perform that action at this time.
0 commit comments