File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -1939,10 +1939,32 @@ bool ByteCodeExprGen<Emitter>::VisitCXXScalarValueInitExpr(
19391939 const CXXScalarValueInitExpr *E) {
19401940 QualType Ty = E->getType ();
19411941
1942- if (Ty->isVoidType ())
1942+ if (DiscardResult || Ty->isVoidType ())
19431943 return true ;
19441944
1945- return this ->visitZeroInitializer (classifyPrim (Ty), Ty, E);
1945+ if (std::optional<PrimType> T = classify (Ty))
1946+ return this ->visitZeroInitializer (*T, Ty, E);
1947+
1948+ assert (Ty->isAnyComplexType ());
1949+ if (!Initializing) {
1950+ std::optional<unsigned > LocalIndex = allocateLocal (E, /* IsExtended=*/ false );
1951+ if (!LocalIndex)
1952+ return false ;
1953+ if (!this ->emitGetPtrLocal (*LocalIndex, E))
1954+ return false ;
1955+ }
1956+
1957+ // Initialize both fields to 0.
1958+ QualType ElemQT = Ty->getAs <ComplexType>()->getElementType ();
1959+ PrimType ElemT = classifyPrim (ElemQT);
1960+
1961+ for (unsigned I = 0 ; I != 2 ; ++I) {
1962+ if (!this ->visitZeroInitializer (ElemT, ElemQT, E))
1963+ return false ;
1964+ if (!this ->emitInitElem (ElemT, I, E))
1965+ return false ;
1966+ }
1967+ return true ;
19461968}
19471969
19481970template <class Emitter >
Original file line number Diff line number Diff line change @@ -179,3 +179,18 @@ namespace Sub {
179179}
180180
181181}
182+
183+ namespace ZeroInit {
184+ typedef _Complex float fcomplex;
185+ typedef _Complex unsigned icomplex;
186+
187+ constexpr fcomplex test7 = fcomplex();
188+ static_assert (__real(test7) == 0 .0f , " " );
189+ static_assert (__imag(test7) == 0 .0f , " " );
190+
191+ constexpr icomplex test8 = icomplex();
192+ static_assert (__real(test8) == 0 , " " );
193+ static_assert (__imag(test8) == 0 , " " );
194+
195+ constexpr int ignored = (fcomplex(), 0 );
196+ }
You can’t perform that action at this time.
0 commit comments