blob: 5d40e43039ac1808af1a2b94bac7e74730f6f5d4 [file] [log] [blame]
Steve Naroffc4d4a482008-05-01 22:18:59 +00001//===--- SemaInit.cpp - Semantic Analysis for Initializers ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Douglas Gregoraaa20962009-01-29 01:05:33 +000010// This file implements semantic analysis for initializers. The entry
11// point is Sema::CheckInitList(), but all of the work is performed
12// within the InitListChecker class.
Steve Naroffc4d4a482008-05-01 22:18:59 +000013//
14//===----------------------------------------------------------------------===//
15
16#include "Sema.h"
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +000017#include "clang/Parse/Designator.h"
Steve Naroffc4d4a482008-05-01 22:18:59 +000018#include "clang/AST/ASTContext.h"
19#include "clang/AST/Expr.h"
Douglas Gregor849afc32009-01-29 00:45:39 +000020#include <map>
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +000021using namespace clang;
Steve Naroffc4d4a482008-05-01 22:18:59 +000022
Douglas Gregoraaa20962009-01-29 01:05:33 +000023/// @brief Semantic checking for initializer lists.
24///
25/// The InitListChecker class contains a set of routines that each
26/// handle the initialization of a certain kind of entity, e.g.,
27/// arrays, vectors, struct/union types, scalars, etc. The
28/// InitListChecker itself performs a recursive walk of the subobject
29/// structure of the type to be initialized, while stepping through
30/// the initializer list one element at a time. The IList and Index
31/// parameters to each of the Check* routines contain the active
32/// (syntactic) initializer list and the index into that initializer
33/// list that represents the current initializer. Each routine is
34/// responsible for moving that Index forward as it consumes elements.
35///
36/// Each Check* routine also has a StructuredList/StructuredIndex
37/// arguments, which contains the current the "structured" (semantic)
38/// initializer list and the index into that initializer list where we
39/// are copying initializers as we map them over to the semantic
40/// list. Once we have completed our recursive walk of the subobject
41/// structure, we will have constructed a full semantic initializer
42/// list.
43///
44/// C99 designators cause changes in the initializer list traversal,
45/// because they make the initialization "jump" into a specific
46/// subobject and then continue the initialization from that
47/// point. CheckDesignatedInitializer() recursively steps into the
48/// designated subobject and manages backing out the recursion to
49/// initialize the subobjects after the one designated.
Chris Lattner1aa25a72009-01-29 05:10:57 +000050namespace clang {
Douglas Gregor849afc32009-01-29 00:45:39 +000051class InitListChecker {
52 Sema *SemaRef;
53 bool hadError;
54 std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic;
55 InitListExpr *FullyStructuredList;
56
57 void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
Douglas Gregoraaa20962009-01-29 01:05:33 +000058 unsigned &Index, InitListExpr *StructuredList,
59 unsigned &StructuredIndex);
Douglas Gregor849afc32009-01-29 00:45:39 +000060 void CheckExplicitInitList(InitListExpr *IList, QualType &T,
Douglas Gregoraaa20962009-01-29 01:05:33 +000061 unsigned &Index, InitListExpr *StructuredList,
62 unsigned &StructuredIndex);
Douglas Gregor849afc32009-01-29 00:45:39 +000063 void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
64 bool SubobjectIsDesignatorContext,
65 unsigned &Index,
Douglas Gregoraaa20962009-01-29 01:05:33 +000066 InitListExpr *StructuredList,
67 unsigned &StructuredIndex);
Douglas Gregor849afc32009-01-29 00:45:39 +000068 void CheckSubElementType(InitListExpr *IList, QualType ElemType,
69 unsigned &Index,
Douglas Gregoraaa20962009-01-29 01:05:33 +000070 InitListExpr *StructuredList,
71 unsigned &StructuredIndex);
Douglas Gregord45210d2009-01-30 22:09:00 +000072 void CheckScalarType(InitListExpr *IList, QualType DeclType,
Douglas Gregor849afc32009-01-29 00:45:39 +000073 unsigned &Index,
Douglas Gregoraaa20962009-01-29 01:05:33 +000074 InitListExpr *StructuredList,
75 unsigned &StructuredIndex);
Douglas Gregord45210d2009-01-30 22:09:00 +000076 void CheckReferenceType(InitListExpr *IList, QualType DeclType,
77 unsigned &Index,
78 InitListExpr *StructuredList,
79 unsigned &StructuredIndex);
Douglas Gregor849afc32009-01-29 00:45:39 +000080 void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index,
Douglas Gregoraaa20962009-01-29 01:05:33 +000081 InitListExpr *StructuredList,
82 unsigned &StructuredIndex);
Douglas Gregor849afc32009-01-29 00:45:39 +000083 void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
84 RecordDecl::field_iterator Field,
85 bool SubobjectIsDesignatorContext, unsigned &Index,
Douglas Gregoraaa20962009-01-29 01:05:33 +000086 InitListExpr *StructuredList,
87 unsigned &StructuredIndex);
Douglas Gregor849afc32009-01-29 00:45:39 +000088 void CheckArrayType(InitListExpr *IList, QualType &DeclType,
89 llvm::APSInt elementIndex,
90 bool SubobjectIsDesignatorContext, unsigned &Index,
Douglas Gregoraaa20962009-01-29 01:05:33 +000091 InitListExpr *StructuredList,
92 unsigned &StructuredIndex);
Douglas Gregor849afc32009-01-29 00:45:39 +000093 bool CheckDesignatedInitializer(InitListExpr *IList, DesignatedInitExpr *DIE,
94 DesignatedInitExpr::designators_iterator D,
95 QualType &CurrentObjectType,
96 RecordDecl::field_iterator *NextField,
97 llvm::APSInt *NextElementIndex,
98 unsigned &Index,
99 InitListExpr *StructuredList,
100 unsigned &StructuredIndex,
101 bool FinishSubobjectInit = true);
102 InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
103 QualType CurrentObjectType,
104 InitListExpr *StructuredList,
105 unsigned StructuredIndex,
106 SourceRange InitRange);
Douglas Gregoraaa20962009-01-29 01:05:33 +0000107 void UpdateStructuredListElement(InitListExpr *StructuredList,
108 unsigned &StructuredIndex,
Douglas Gregor849afc32009-01-29 00:45:39 +0000109 Expr *expr);
110 int numArrayElements(QualType DeclType);
111 int numStructUnionElements(QualType DeclType);
Douglas Gregord45210d2009-01-30 22:09:00 +0000112
113 void FillInValueInitializations(InitListExpr *ILE);
Douglas Gregor849afc32009-01-29 00:45:39 +0000114public:
115 InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
116 bool HadError() { return hadError; }
117
118 // @brief Retrieves the fully-structured initializer list used for
119 // semantic analysis and code generation.
120 InitListExpr *getFullyStructuredList() const { return FullyStructuredList; }
121};
Chris Lattner1aa25a72009-01-29 05:10:57 +0000122}
123
Douglas Gregorf603b472009-01-28 21:54:33 +0000124/// Recursively replaces NULL values within the given initializer list
125/// with expressions that perform value-initialization of the
126/// appropriate type.
Douglas Gregord45210d2009-01-30 22:09:00 +0000127void InitListChecker::FillInValueInitializations(InitListExpr *ILE) {
128 assert((ILE->getType() != SemaRef->Context.VoidTy) &&
129 "Should not have void type");
Douglas Gregorf603b472009-01-28 21:54:33 +0000130 if (const RecordType *RType = ILE->getType()->getAsRecordType()) {
131 unsigned Init = 0, NumInits = ILE->getNumInits();
132 for (RecordDecl::field_iterator Field = RType->getDecl()->field_begin(),
133 FieldEnd = RType->getDecl()->field_end();
134 Field != FieldEnd; ++Field) {
135 if (Field->isUnnamedBitfield())
136 continue;
137
Douglas Gregord45210d2009-01-30 22:09:00 +0000138 if (Init >= NumInits) {
139 if (Field->getType()->isReferenceType()) {
140 // C++ [dcl.init.aggr]p9:
141 // If an incomplete or empty initializer-list leaves a
142 // member of reference type uninitialized, the program is
143 // ill-formed.
144 SemaRef->Diag(ILE->getSyntacticForm()->getLocStart(),
145 diag::err_init_reference_member_uninitialized)
146 << Field->getType()
147 << ILE->getSyntacticForm()->getSourceRange();
148 SemaRef->Diag(Field->getLocation(),
149 diag::note_uninit_reference_member);
150 hadError = true;
151 }
152 } else if (!ILE->getInit(Init))
Douglas Gregorf603b472009-01-28 21:54:33 +0000153 ILE->setInit(Init,
Douglas Gregord45210d2009-01-30 22:09:00 +0000154 new (SemaRef->Context) ImplicitValueInitExpr(Field->getType()));
Douglas Gregorc9e012a2009-01-29 17:44:32 +0000155 else if (InitListExpr *InnerILE
156 = dyn_cast<InitListExpr>(ILE->getInit(Init)))
Douglas Gregord45210d2009-01-30 22:09:00 +0000157 FillInValueInitializations(InnerILE);
Douglas Gregorf603b472009-01-28 21:54:33 +0000158 ++Init;
Douglas Gregord45210d2009-01-30 22:09:00 +0000159
160 // Only look at the first initialization of a union.
161 if (RType->getDecl()->isUnion())
162 break;
Douglas Gregorf603b472009-01-28 21:54:33 +0000163 }
164
165 return;
166 }
167
168 QualType ElementType;
169
Douglas Gregord45210d2009-01-30 22:09:00 +0000170 if (const ArrayType *AType = SemaRef->Context.getAsArrayType(ILE->getType()))
Douglas Gregorf603b472009-01-28 21:54:33 +0000171 ElementType = AType->getElementType();
172 else if (const VectorType *VType = ILE->getType()->getAsVectorType())
173 ElementType = VType->getElementType();
174 else
175 ElementType = ILE->getType();
176
177 for (unsigned Init = 0, NumInits = ILE->getNumInits(); Init != NumInits;
178 ++Init) {
179 if (!ILE->getInit(Init))
Douglas Gregord45210d2009-01-30 22:09:00 +0000180 ILE->setInit(Init,
181 new (SemaRef->Context) ImplicitValueInitExpr(ElementType));
Chris Lattner1aa25a72009-01-29 05:10:57 +0000182 else if (InitListExpr *InnerILE =dyn_cast<InitListExpr>(ILE->getInit(Init)))
Douglas Gregord45210d2009-01-30 22:09:00 +0000183 FillInValueInitializations(InnerILE);
Douglas Gregorf603b472009-01-28 21:54:33 +0000184 }
185}
186
Chris Lattner1aa25a72009-01-29 05:10:57 +0000187
Steve Naroffc4d4a482008-05-01 22:18:59 +0000188InitListChecker::InitListChecker(Sema *S, InitListExpr *IL, QualType &T) {
189 hadError = false;
190 SemaRef = S;
Eli Friedmand8535af2008-05-19 20:00:43 +0000191
Eli Friedman683cedf2008-05-19 19:16:24 +0000192 unsigned newIndex = 0;
Douglas Gregorf603b472009-01-28 21:54:33 +0000193 unsigned newStructuredIndex = 0;
194 FullyStructuredList
195 = getStructuredSubobjectInit(IL, newIndex, T, 0, 0, SourceRange());
196 CheckExplicitInitList(IL, T, newIndex, FullyStructuredList, newStructuredIndex);
Eli Friedmand8535af2008-05-19 20:00:43 +0000197
Douglas Gregord45210d2009-01-30 22:09:00 +0000198 if (!hadError)
199 FillInValueInitializations(FullyStructuredList);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000200}
201
202int InitListChecker::numArrayElements(QualType DeclType) {
Eli Friedman46f81662008-05-25 13:22:35 +0000203 // FIXME: use a proper constant
204 int maxElements = 0x7FFFFFFF;
Chris Lattnera1923f62008-08-04 07:31:14 +0000205 if (const ConstantArrayType *CAT =
206 SemaRef->Context.getAsConstantArrayType(DeclType)) {
Steve Naroffc4d4a482008-05-01 22:18:59 +0000207 maxElements = static_cast<int>(CAT->getSize().getZExtValue());
208 }
209 return maxElements;
210}
211
212int InitListChecker::numStructUnionElements(QualType DeclType) {
213 RecordDecl *structDecl = DeclType->getAsRecordType()->getDecl();
Douglas Gregorf603b472009-01-28 21:54:33 +0000214 int InitializableMembers = 0;
215 for (RecordDecl::field_iterator Field = structDecl->field_begin(),
216 FieldEnd = structDecl->field_end();
217 Field != FieldEnd; ++Field) {
218 if ((*Field)->getIdentifier() || !(*Field)->isBitField())
219 ++InitializableMembers;
220 }
Argiris Kirtzidisc6cc7d52008-06-09 23:19:58 +0000221 if (structDecl->isUnion())
Eli Friedman9f5250b2008-05-25 14:03:31 +0000222 return std::min(InitializableMembers, 1);
223 return InitializableMembers - structDecl->hasFlexibleArrayMember();
Steve Naroffc4d4a482008-05-01 22:18:59 +0000224}
225
226void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList,
Douglas Gregorf603b472009-01-28 21:54:33 +0000227 QualType T, unsigned &Index,
228 InitListExpr *StructuredList,
229 unsigned &StructuredIndex) {
Steve Naroffc4d4a482008-05-01 22:18:59 +0000230 int maxElements = 0;
231
232 if (T->isArrayType())
233 maxElements = numArrayElements(T);
234 else if (T->isStructureType() || T->isUnionType())
235 maxElements = numStructUnionElements(T);
Eli Friedman683cedf2008-05-19 19:16:24 +0000236 else if (T->isVectorType())
237 maxElements = T->getAsVectorType()->getNumElements();
Steve Naroffc4d4a482008-05-01 22:18:59 +0000238 else
239 assert(0 && "CheckImplicitInitList(): Illegal type");
Eli Friedman683cedf2008-05-19 19:16:24 +0000240
Eli Friedmanf8df28c2008-05-25 13:49:22 +0000241 if (maxElements == 0) {
242 SemaRef->Diag(ParentIList->getInit(Index)->getLocStart(),
243 diag::err_implicit_empty_initializer);
Douglas Gregorf603b472009-01-28 21:54:33 +0000244 ++Index;
Eli Friedmanf8df28c2008-05-25 13:49:22 +0000245 hadError = true;
246 return;
247 }
248
Douglas Gregorf603b472009-01-28 21:54:33 +0000249 // Build a structured initializer list corresponding to this subobject.
250 InitListExpr *StructuredSubobjectInitList
251 = getStructuredSubobjectInit(ParentIList, Index, T, StructuredList,
252 StructuredIndex,
253 ParentIList->getInit(Index)->getSourceRange());
254 unsigned StructuredSubobjectInitIndex = 0;
Eli Friedman683cedf2008-05-19 19:16:24 +0000255
Douglas Gregorf603b472009-01-28 21:54:33 +0000256 // Check the element types and build the structural subobject.
257 CheckListElementTypes(ParentIList, T, false, Index,
258 StructuredSubobjectInitList,
259 StructuredSubobjectInitIndex);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000260}
261
Steve Naroff56099522008-05-06 00:23:44 +0000262void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T,
Douglas Gregorf603b472009-01-28 21:54:33 +0000263 unsigned &Index,
264 InitListExpr *StructuredList,
265 unsigned &StructuredIndex) {
Eli Friedmand8535af2008-05-19 20:00:43 +0000266 assert(IList->isExplicit() && "Illegal Implicit InitListExpr");
Douglas Gregorf603b472009-01-28 21:54:33 +0000267 SyntacticToSemantic[IList] = StructuredList;
268 StructuredList->setSyntacticForm(IList);
269 CheckListElementTypes(IList, T, true, Index, StructuredList,
270 StructuredIndex);
Steve Naroff56099522008-05-06 00:23:44 +0000271 IList->setType(T);
Douglas Gregorf603b472009-01-28 21:54:33 +0000272 StructuredList->setType(T);
Eli Friedman46f81662008-05-25 13:22:35 +0000273 if (hadError)
274 return;
Eli Friedmand8535af2008-05-19 20:00:43 +0000275
Eli Friedman46f81662008-05-25 13:22:35 +0000276 if (Index < IList->getNumInits()) {
Eli Friedmand8535af2008-05-19 20:00:43 +0000277 // We have leftover initializers
278 if (IList->getNumInits() > 0 &&
279 SemaRef->IsStringLiteralInit(IList->getInit(Index), T)) {
Eli Friedman71de9eb2008-05-19 20:12:18 +0000280 // Special-case
Eli Friedmand8535af2008-05-19 20:00:43 +0000281 SemaRef->Diag(IList->getInit(Index)->getLocStart(),
Chris Lattner9d2cf082008-11-19 05:27:50 +0000282 diag::err_excess_initializers_in_char_array_initializer)
283 << IList->getInit(Index)->getSourceRange();
Eli Friedmand8535af2008-05-19 20:00:43 +0000284 hadError = true;
Eli Friedmanb9ea6bc2008-05-20 05:25:56 +0000285 } else if (!T->isIncompleteType()) {
286 // Don't warn for incomplete types, since we'll get an error elsewhere
Eli Friedmand8535af2008-05-19 20:00:43 +0000287 SemaRef->Diag(IList->getInit(Index)->getLocStart(),
Chris Lattner9d2cf082008-11-19 05:27:50 +0000288 diag::warn_excess_initializers)
289 << IList->getInit(Index)->getSourceRange();
Eli Friedmand8535af2008-05-19 20:00:43 +0000290 }
291 }
Eli Friedman455f7622008-05-19 20:20:43 +0000292
Eli Friedman46f81662008-05-25 13:22:35 +0000293 if (T->isScalarType())
Chris Lattner9d2cf082008-11-19 05:27:50 +0000294 SemaRef->Diag(IList->getLocStart(), diag::warn_braces_around_scalar_init)
295 << IList->getSourceRange();
Steve Naroffc4d4a482008-05-01 22:18:59 +0000296}
297
Eli Friedman683cedf2008-05-19 19:16:24 +0000298void InitListChecker::CheckListElementTypes(InitListExpr *IList,
299 QualType &DeclType,
Douglas Gregor710f6d42009-01-22 23:26:18 +0000300 bool SubobjectIsDesignatorContext,
Douglas Gregorf603b472009-01-28 21:54:33 +0000301 unsigned &Index,
302 InitListExpr *StructuredList,
303 unsigned &StructuredIndex) {
Eli Friedmand8535af2008-05-19 20:00:43 +0000304 if (DeclType->isScalarType()) {
Douglas Gregor36859eb2009-01-29 00:39:20 +0000305 CheckScalarType(IList, DeclType, Index, StructuredList, StructuredIndex);
Eli Friedmand8535af2008-05-19 20:00:43 +0000306 } else if (DeclType->isVectorType()) {
Douglas Gregorf603b472009-01-28 21:54:33 +0000307 CheckVectorType(IList, DeclType, Index, StructuredList, StructuredIndex);
Douglas Gregore7ef5002009-01-30 17:31:00 +0000308 } else if (DeclType->isAggregateType()) {
309 if (DeclType->isRecordType()) {
Douglas Gregor710f6d42009-01-22 23:26:18 +0000310 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
311 CheckStructUnionTypes(IList, DeclType, RD->field_begin(),
Douglas Gregorf603b472009-01-28 21:54:33 +0000312 SubobjectIsDesignatorContext, Index,
313 StructuredList, StructuredIndex);
Douglas Gregor710f6d42009-01-22 23:26:18 +0000314 } else if (DeclType->isArrayType()) {
Douglas Gregor5a203a62009-01-23 16:54:12 +0000315 llvm::APSInt Zero(
316 SemaRef->Context.getTypeSize(SemaRef->Context.getSizeType()),
317 false);
Douglas Gregorf603b472009-01-28 21:54:33 +0000318 CheckArrayType(IList, DeclType, Zero, SubobjectIsDesignatorContext, Index,
319 StructuredList, StructuredIndex);
Douglas Gregor710f6d42009-01-22 23:26:18 +0000320 }
Steve Naroffc4d4a482008-05-01 22:18:59 +0000321 else
Douglas Gregorf603b472009-01-28 21:54:33 +0000322 assert(0 && "Aggregate that isn't a structure or array?!");
Steve Naroffff5b3a82008-08-10 16:05:48 +0000323 } else if (DeclType->isVoidType() || DeclType->isFunctionType()) {
324 // This type is invalid, issue a diagnostic.
Douglas Gregorf603b472009-01-28 21:54:33 +0000325 ++Index;
Chris Lattner10f2c2e2008-11-20 06:38:18 +0000326 SemaRef->Diag(IList->getLocStart(), diag::err_illegal_initializer_type)
Chris Lattner4bfd2232008-11-24 06:25:27 +0000327 << DeclType;
Eli Friedmanb9ea6bc2008-05-20 05:25:56 +0000328 hadError = true;
Douglas Gregord45210d2009-01-30 22:09:00 +0000329 } else if (DeclType->isRecordType()) {
330 // C++ [dcl.init]p14:
331 // [...] If the class is an aggregate (8.5.1), and the initializer
332 // is a brace-enclosed list, see 8.5.1.
333 //
334 // Note: 8.5.1 is handled below; here, we diagnose the case where
335 // we have an initializer list and a destination type that is not
336 // an aggregate.
337 // FIXME: In C++0x, this is yet another form of initialization.
338 SemaRef->Diag(IList->getLocStart(), diag::err_init_non_aggr_init_list)
339 << DeclType << IList->getSourceRange();
340 hadError = true;
341 } else if (DeclType->isReferenceType()) {
342 CheckReferenceType(IList, DeclType, Index, StructuredList, StructuredIndex);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000343 } else {
344 // In C, all types are either scalars or aggregates, but
345 // additional handling is needed here for C++ (and possibly others?).
346 assert(0 && "Unsupported initializer type");
347 }
348}
349
Eli Friedman683cedf2008-05-19 19:16:24 +0000350void InitListChecker::CheckSubElementType(InitListExpr *IList,
351 QualType ElemType,
Douglas Gregorf603b472009-01-28 21:54:33 +0000352 unsigned &Index,
353 InitListExpr *StructuredList,
354 unsigned &StructuredIndex) {
Douglas Gregor36859eb2009-01-29 00:39:20 +0000355 Expr *expr = IList->getInit(Index);
Eli Friedmand8535af2008-05-19 20:00:43 +0000356 if (InitListExpr *SubInitList = dyn_cast<InitListExpr>(expr)) {
357 unsigned newIndex = 0;
Douglas Gregorf603b472009-01-28 21:54:33 +0000358 unsigned newStructuredIndex = 0;
359 InitListExpr *newStructuredList
360 = getStructuredSubobjectInit(IList, Index, ElemType,
361 StructuredList, StructuredIndex,
362 SubInitList->getSourceRange());
363 CheckExplicitInitList(SubInitList, ElemType, newIndex,
364 newStructuredList, newStructuredIndex);
365 ++StructuredIndex;
366 ++Index;
Eli Friedman683cedf2008-05-19 19:16:24 +0000367 } else if (StringLiteral *lit =
368 SemaRef->IsStringLiteralInit(expr, ElemType)) {
369 SemaRef->CheckStringLiteralInit(lit, ElemType);
Douglas Gregorf603b472009-01-28 21:54:33 +0000370 UpdateStructuredListElement(StructuredList, StructuredIndex, lit);
371 ++Index;
Eli Friedmand8535af2008-05-19 20:00:43 +0000372 } else if (ElemType->isScalarType()) {
Douglas Gregor36859eb2009-01-29 00:39:20 +0000373 CheckScalarType(IList, ElemType, Index, StructuredList, StructuredIndex);
Douglas Gregord45210d2009-01-30 22:09:00 +0000374 } else if (ElemType->isReferenceType()) {
375 CheckReferenceType(IList, ElemType, Index, StructuredList, StructuredIndex);
Eli Friedman683cedf2008-05-19 19:16:24 +0000376 } else {
Douglas Gregord45210d2009-01-30 22:09:00 +0000377 if (SemaRef->getLangOptions().CPlusPlus) {
378 // C++ [dcl.init.aggr]p12:
379 // All implicit type conversions (clause 4) are considered when
380 // initializing the aggregate member with an ini- tializer from
381 // an initializer-list. If the initializer can initialize a
382 // member, the member is initialized. [...]
383 ImplicitConversionSequence ICS
384 = SemaRef->TryCopyInitialization(expr, ElemType);
385 if (ICS.ConversionKind != ImplicitConversionSequence::BadConversion) {
386 if (SemaRef->PerformImplicitConversion(expr, ElemType, ICS,
387 "initializing"))
388 hadError = true;
389 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
390 ++Index;
391 return;
392 }
393
394 // Fall through for subaggregate initialization
395 } else {
396 // C99 6.7.8p13:
397 //
398 // The initializer for a structure or union object that has
399 // automatic storage duration shall be either an initializer
400 // list as described below, or a single expression that has
401 // compatible structure or union type. In the latter case, the
402 // initial value of the object, including unnamed members, is
403 // that of the expression.
404 QualType ExprType = SemaRef->Context.getCanonicalType(expr->getType());
405 QualType ElemTypeCanon = SemaRef->Context.getCanonicalType(ElemType);
406 if (SemaRef->Context.typesAreCompatible(ExprType.getUnqualifiedType(),
407 ElemTypeCanon.getUnqualifiedType())) {
408 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
409 ++Index;
410 return;
411 }
412
413 // Fall through for subaggregate initialization
414 }
415
416 // C++ [dcl.init.aggr]p12:
417 //
418 // [...] Otherwise, if the member is itself a non-empty
419 // subaggregate, brace elision is assumed and the initializer is
420 // considered for the initialization of the first member of
421 // the subaggregate.
422 if (ElemType->isAggregateType() || ElemType->isVectorType()) {
423 CheckImplicitInitList(IList, ElemType, Index, StructuredList,
424 StructuredIndex);
425 ++StructuredIndex;
426 } else {
427 // We cannot initialize this element, so let
428 // PerformCopyInitialization produce the appropriate diagnostic.
429 SemaRef->PerformCopyInitialization(expr, ElemType, "initializing");
430 hadError = true;
431 ++Index;
432 ++StructuredIndex;
433 }
434 }
Eli Friedman683cedf2008-05-19 19:16:24 +0000435}
436
Douglas Gregord45210d2009-01-30 22:09:00 +0000437void InitListChecker::CheckScalarType(InitListExpr *IList, QualType DeclType,
Douglas Gregor36859eb2009-01-29 00:39:20 +0000438 unsigned &Index,
Douglas Gregorf603b472009-01-28 21:54:33 +0000439 InitListExpr *StructuredList,
440 unsigned &StructuredIndex) {
Steve Naroffc4d4a482008-05-01 22:18:59 +0000441 if (Index < IList->getNumInits()) {
Douglas Gregor36859eb2009-01-29 00:39:20 +0000442 Expr *expr = IList->getInit(Index);
Eli Friedmand8535af2008-05-19 20:00:43 +0000443 if (isa<InitListExpr>(expr)) {
Eli Friedman71de9eb2008-05-19 20:12:18 +0000444 SemaRef->Diag(IList->getLocStart(),
Chris Lattner9d2cf082008-11-19 05:27:50 +0000445 diag::err_many_braces_around_scalar_init)
446 << IList->getSourceRange();
Eli Friedman71de9eb2008-05-19 20:12:18 +0000447 hadError = true;
448 ++Index;
Douglas Gregorf603b472009-01-28 21:54:33 +0000449 ++StructuredIndex;
Eli Friedman71de9eb2008-05-19 20:12:18 +0000450 return;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000451 } else if (isa<DesignatedInitExpr>(expr)) {
452 SemaRef->Diag(expr->getSourceRange().getBegin(),
453 diag::err_designator_for_scalar_init)
454 << DeclType << expr->getSourceRange();
455 hadError = true;
456 ++Index;
Douglas Gregorf603b472009-01-28 21:54:33 +0000457 ++StructuredIndex;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000458 return;
Steve Naroffc4d4a482008-05-01 22:18:59 +0000459 }
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000460
Eli Friedmand8535af2008-05-19 20:00:43 +0000461 Expr *savExpr = expr; // Might be promoted by CheckSingleInitializer.
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000462 if (SemaRef->CheckSingleInitializer(expr, DeclType, false))
Eli Friedman71de9eb2008-05-19 20:12:18 +0000463 hadError = true; // types weren't compatible.
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000464 else if (savExpr != expr) {
Eli Friedmand8535af2008-05-19 20:00:43 +0000465 // The type was promoted, update initializer list.
Douglas Gregor36859eb2009-01-29 00:39:20 +0000466 IList->setInit(Index, expr);
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000467 }
Douglas Gregorf603b472009-01-28 21:54:33 +0000468 if (hadError)
469 ++StructuredIndex;
470 else
471 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000472 ++Index;
Eli Friedman71de9eb2008-05-19 20:12:18 +0000473 } else {
Chris Lattner9d2cf082008-11-19 05:27:50 +0000474 SemaRef->Diag(IList->getLocStart(), diag::err_empty_scalar_initializer)
475 << IList->getSourceRange();
Eli Friedman71de9eb2008-05-19 20:12:18 +0000476 hadError = true;
Douglas Gregorf603b472009-01-28 21:54:33 +0000477 ++Index;
478 ++StructuredIndex;
Eli Friedman71de9eb2008-05-19 20:12:18 +0000479 return;
Steve Naroffc4d4a482008-05-01 22:18:59 +0000480 }
Steve Naroffc4d4a482008-05-01 22:18:59 +0000481}
482
Douglas Gregord45210d2009-01-30 22:09:00 +0000483void InitListChecker::CheckReferenceType(InitListExpr *IList, QualType DeclType,
484 unsigned &Index,
485 InitListExpr *StructuredList,
486 unsigned &StructuredIndex) {
487 if (Index < IList->getNumInits()) {
488 Expr *expr = IList->getInit(Index);
489 if (isa<InitListExpr>(expr)) {
490 SemaRef->Diag(IList->getLocStart(), diag::err_init_non_aggr_init_list)
491 << DeclType << IList->getSourceRange();
492 hadError = true;
493 ++Index;
494 ++StructuredIndex;
495 return;
496 }
497
498 Expr *savExpr = expr; // Might be promoted by CheckSingleInitializer.
499 if (SemaRef->CheckReferenceInit(expr, DeclType))
500 hadError = true;
501 else if (savExpr != expr) {
502 // The type was promoted, update initializer list.
503 IList->setInit(Index, expr);
504 }
505 if (hadError)
506 ++StructuredIndex;
507 else
508 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
509 ++Index;
510 } else {
511 // FIXME: It would be wonderful if we could point at the actual
512 // member. In general, it would be useful to pass location
513 // information down the stack, so that we know the location (or
514 // decl) of the "current object" being initialized.
515 SemaRef->Diag(IList->getLocStart(),
516 diag::err_init_reference_member_uninitialized)
517 << DeclType
518 << IList->getSourceRange();
519 hadError = true;
520 ++Index;
521 ++StructuredIndex;
522 return;
523 }
524}
525
Steve Naroffc4d4a482008-05-01 22:18:59 +0000526void InitListChecker::CheckVectorType(InitListExpr *IList, QualType DeclType,
Douglas Gregorf603b472009-01-28 21:54:33 +0000527 unsigned &Index,
528 InitListExpr *StructuredList,
529 unsigned &StructuredIndex) {
Steve Naroffc4d4a482008-05-01 22:18:59 +0000530 if (Index < IList->getNumInits()) {
531 const VectorType *VT = DeclType->getAsVectorType();
532 int maxElements = VT->getNumElements();
533 QualType elementType = VT->getElementType();
534
535 for (int i = 0; i < maxElements; ++i) {
536 // Don't attempt to go past the end of the init list
537 if (Index >= IList->getNumInits())
538 break;
Douglas Gregor36859eb2009-01-29 00:39:20 +0000539 CheckSubElementType(IList, elementType, Index,
Douglas Gregorf603b472009-01-28 21:54:33 +0000540 StructuredList, StructuredIndex);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000541 }
542 }
543}
544
545void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
Douglas Gregor710f6d42009-01-22 23:26:18 +0000546 llvm::APSInt elementIndex,
547 bool SubobjectIsDesignatorContext,
Douglas Gregorf603b472009-01-28 21:54:33 +0000548 unsigned &Index,
549 InitListExpr *StructuredList,
550 unsigned &StructuredIndex) {
Steve Naroffc4d4a482008-05-01 22:18:59 +0000551 // Check for the special-case of initializing an array with a string.
552 if (Index < IList->getNumInits()) {
553 if (StringLiteral *lit =
554 SemaRef->IsStringLiteralInit(IList->getInit(Index), DeclType)) {
555 SemaRef->CheckStringLiteralInit(lit, DeclType);
Douglas Gregorf603b472009-01-28 21:54:33 +0000556 // We place the string literal directly into the resulting
557 // initializer list. This is the only place where the structure
558 // of the structured initializer list doesn't match exactly,
559 // because doing so would involve allocating one character
560 // constant for each string.
561 UpdateStructuredListElement(StructuredList, StructuredIndex, lit);
562 StructuredList->resizeInits(SemaRef->Context, StructuredIndex);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000563 ++Index;
Steve Naroffc4d4a482008-05-01 22:18:59 +0000564 return;
565 }
566 }
Chris Lattnera1923f62008-08-04 07:31:14 +0000567 if (const VariableArrayType *VAT =
568 SemaRef->Context.getAsVariableArrayType(DeclType)) {
Eli Friedman46f81662008-05-25 13:22:35 +0000569 // Check for VLAs; in standard C it would be possible to check this
570 // earlier, but I don't know where clang accepts VLAs (gcc accepts
571 // them in all sorts of strange places).
572 SemaRef->Diag(VAT->getSizeExpr()->getLocStart(),
Chris Lattner9d2cf082008-11-19 05:27:50 +0000573 diag::err_variable_object_no_init)
574 << VAT->getSizeExpr()->getSourceRange();
Eli Friedman46f81662008-05-25 13:22:35 +0000575 hadError = true;
Douglas Gregorf603b472009-01-28 21:54:33 +0000576 ++Index;
577 ++StructuredIndex;
Eli Friedman46f81662008-05-25 13:22:35 +0000578 return;
579 }
580
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000581 // We might know the maximum number of elements in advance.
Douglas Gregorf603b472009-01-28 21:54:33 +0000582 llvm::APSInt maxElements(elementIndex.getBitWidth(),
583 elementIndex.isUnsigned());
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000584 bool maxElementsKnown = false;
585 if (const ConstantArrayType *CAT =
586 SemaRef->Context.getAsConstantArrayType(DeclType)) {
587 maxElements = CAT->getSize();
Douglas Gregor5a203a62009-01-23 16:54:12 +0000588 elementIndex.extOrTrunc(maxElements.getBitWidth());
Douglas Gregor69722702009-01-23 18:58:42 +0000589 elementIndex.setIsUnsigned(maxElements.isUnsigned());
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000590 maxElementsKnown = true;
591 }
592
Chris Lattnera1923f62008-08-04 07:31:14 +0000593 QualType elementType = SemaRef->Context.getAsArrayType(DeclType)
594 ->getElementType();
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000595 while (Index < IList->getNumInits()) {
596 Expr *Init = IList->getInit(Index);
597 if (DesignatedInitExpr *DIE = dyn_cast<DesignatedInitExpr>(Init)) {
Douglas Gregor710f6d42009-01-22 23:26:18 +0000598 // If we're not the subobject that matches up with the '{' for
599 // the designator, we shouldn't be handling the
600 // designator. Return immediately.
601 if (!SubobjectIsDesignatorContext)
602 return;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000603
Douglas Gregor710f6d42009-01-22 23:26:18 +0000604 // Handle this designated initializer. elementIndex will be
605 // updated to be the next array element we'll initialize.
606 if (CheckDesignatedInitializer(IList, DIE, DIE->designators_begin(),
Douglas Gregorf603b472009-01-28 21:54:33 +0000607 DeclType, 0, &elementIndex, Index,
608 StructuredList, StructuredIndex)) {
Douglas Gregor710f6d42009-01-22 23:26:18 +0000609 hadError = true;
610 continue;
611 }
612
Douglas Gregor5a203a62009-01-23 16:54:12 +0000613 if (elementIndex.getBitWidth() > maxElements.getBitWidth())
614 maxElements.extend(elementIndex.getBitWidth());
615 else if (elementIndex.getBitWidth() < maxElements.getBitWidth())
616 elementIndex.extend(maxElements.getBitWidth());
Douglas Gregor69722702009-01-23 18:58:42 +0000617 elementIndex.setIsUnsigned(maxElements.isUnsigned());
Douglas Gregor5a203a62009-01-23 16:54:12 +0000618
Douglas Gregor710f6d42009-01-22 23:26:18 +0000619 // If the array is of incomplete type, keep track of the number of
620 // elements in the initializer.
621 if (!maxElementsKnown && elementIndex > maxElements)
622 maxElements = elementIndex;
623
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000624 continue;
625 }
626
627 // If we know the maximum number of elements, and we've already
628 // hit it, stop consuming elements in the initializer list.
629 if (maxElementsKnown && elementIndex == maxElements)
Steve Naroffc4d4a482008-05-01 22:18:59 +0000630 break;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000631
632 // Check this element.
Douglas Gregor36859eb2009-01-29 00:39:20 +0000633 CheckSubElementType(IList, elementType, Index,
Douglas Gregorf603b472009-01-28 21:54:33 +0000634 StructuredList, StructuredIndex);
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000635 ++elementIndex;
636
637 // If the array is of incomplete type, keep track of the number of
638 // elements in the initializer.
639 if (!maxElementsKnown && elementIndex > maxElements)
640 maxElements = elementIndex;
Steve Naroffc4d4a482008-05-01 22:18:59 +0000641 }
642 if (DeclType->isIncompleteArrayType()) {
643 // If this is an incomplete array type, the actual type needs to
Daniel Dunbar604dacf2008-08-18 20:28:46 +0000644 // be calculated here.
Douglas Gregor69722702009-01-23 18:58:42 +0000645 llvm::APSInt Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000646 if (maxElements == Zero) {
Daniel Dunbar604dacf2008-08-18 20:28:46 +0000647 // Sizing an array implicitly to zero is not allowed by ISO C,
648 // but is supported by GNU.
Steve Naroffc4d4a482008-05-01 22:18:59 +0000649 SemaRef->Diag(IList->getLocStart(),
Daniel Dunbar604dacf2008-08-18 20:28:46 +0000650 diag::ext_typecheck_zero_array_size);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000651 }
Daniel Dunbar604dacf2008-08-18 20:28:46 +0000652
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000653 DeclType = SemaRef->Context.getConstantArrayType(elementType, maxElements,
Daniel Dunbar604dacf2008-08-18 20:28:46 +0000654 ArrayType::Normal, 0);
Steve Naroffc4d4a482008-05-01 22:18:59 +0000655 }
656}
657
658void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,
659 QualType DeclType,
Douglas Gregor710f6d42009-01-22 23:26:18 +0000660 RecordDecl::field_iterator Field,
661 bool SubobjectIsDesignatorContext,
Douglas Gregorf603b472009-01-28 21:54:33 +0000662 unsigned &Index,
663 InitListExpr *StructuredList,
664 unsigned &StructuredIndex) {
Eli Friedman683cedf2008-05-19 19:16:24 +0000665 RecordDecl* structDecl = DeclType->getAsRecordType()->getDecl();
Steve Naroffc4d4a482008-05-01 22:18:59 +0000666
Eli Friedman683cedf2008-05-19 19:16:24 +0000667 // If the record is invalid, some of it's members are invalid. To avoid
668 // confusion, we forgo checking the intializer for the entire record.
669 if (structDecl->isInvalidDecl()) {
670 hadError = true;
671 return;
672 }
Douglas Gregorc9e012a2009-01-29 17:44:32 +0000673
674 if (DeclType->isUnionType() && IList->getNumInits() == 0) {
675 // Value-initialize the first named member of the union.
676 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
677 for (RecordDecl::field_iterator FieldEnd = RD->field_end();
678 Field != FieldEnd; ++Field) {
679 if (Field->getDeclName()) {
680 StructuredList->setInitializedFieldInUnion(*Field);
681 break;
682 }
683 }
684 return;
685 }
686
687
688
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000689 // If structDecl is a forward declaration, this loop won't do
690 // anything except look at designated initializers; That's okay,
691 // because an error should get printed out elsewhere. It might be
692 // worthwhile to skip over the rest of the initializer, though.
Douglas Gregor8acb7272008-12-11 16:49:14 +0000693 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
Douglas Gregor710f6d42009-01-22 23:26:18 +0000694 RecordDecl::field_iterator FieldEnd = RD->field_end();
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000695 while (Index < IList->getNumInits()) {
696 Expr *Init = IList->getInit(Index);
697
698 if (DesignatedInitExpr *DIE = dyn_cast<DesignatedInitExpr>(Init)) {
Douglas Gregor710f6d42009-01-22 23:26:18 +0000699 // If we're not the subobject that matches up with the '{' for
700 // the designator, we shouldn't be handling the
701 // designator. Return immediately.
702 if (!SubobjectIsDesignatorContext)
703 return;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000704
Douglas Gregor710f6d42009-01-22 23:26:18 +0000705 // Handle this designated initializer. Field will be updated to
706 // the next field that we'll be initializing.
707 if (CheckDesignatedInitializer(IList, DIE, DIE->designators_begin(),
Douglas Gregorf603b472009-01-28 21:54:33 +0000708 DeclType, &Field, 0, Index,
709 StructuredList, StructuredIndex))
Douglas Gregor710f6d42009-01-22 23:26:18 +0000710 hadError = true;
711
Douglas Gregor82462762009-01-29 16:53:55 +0000712 // Abort early for unions: the designator handled the
713 // initialization of the appropriate field.
714 if (DeclType->isUnionType())
715 break;
716
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000717 continue;
718 }
719
720 if (Field == FieldEnd) {
721 // We've run out of fields. We're done.
722 break;
723 }
724
Douglas Gregor8acb7272008-12-11 16:49:14 +0000725 // If we've hit the flexible array member at the end, we're done.
726 if (Field->getType()->isIncompleteArrayType())
727 break;
728
Douglas Gregor82462762009-01-29 16:53:55 +0000729 if (Field->isUnnamedBitfield()) {
Douglas Gregorf603b472009-01-28 21:54:33 +0000730 // Don't initialize unnamed bitfields, e.g. "int : 20;"
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000731 ++Field;
Eli Friedman683cedf2008-05-19 19:16:24 +0000732 continue;
Steve Naroffc4d4a482008-05-01 22:18:59 +0000733 }
Douglas Gregor8acb7272008-12-11 16:49:14 +0000734
Douglas Gregor36859eb2009-01-29 00:39:20 +0000735 CheckSubElementType(IList, Field->getType(), Index,
Douglas Gregorf603b472009-01-28 21:54:33 +0000736 StructuredList, StructuredIndex);
Douglas Gregor82462762009-01-29 16:53:55 +0000737
738 if (DeclType->isUnionType()) {
739 // Initialize the first field within the union.
740 StructuredList->setInitializedFieldInUnion(*Field);
Eli Friedman683cedf2008-05-19 19:16:24 +0000741 break;
Douglas Gregor82462762009-01-29 16:53:55 +0000742 }
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000743
744 ++Field;
Steve Naroffc4d4a482008-05-01 22:18:59 +0000745 }
Douglas Gregor8acb7272008-12-11 16:49:14 +0000746
Eli Friedman683cedf2008-05-19 19:16:24 +0000747 // FIXME: Implement flexible array initialization GCC extension (it's a
748 // really messy extension to implement, unfortunately...the necessary
749 // information isn't actually even here!)
Steve Naroffc4d4a482008-05-01 22:18:59 +0000750}
Steve Naroffc4d4a482008-05-01 22:18:59 +0000751
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000752/// @brief Check the well-formedness of a C99 designated initializer.
753///
754/// Determines whether the designated initializer @p DIE, which
755/// resides at the given @p Index within the initializer list @p
756/// IList, is well-formed for a current object of type @p DeclType
757/// (C99 6.7.8). The actual subobject that this designator refers to
758/// within the current subobject is returned in either
Douglas Gregorf603b472009-01-28 21:54:33 +0000759/// @p NextField or @p NextElementIndex (whichever is appropriate).
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000760///
761/// @param IList The initializer list in which this designated
762/// initializer occurs.
763///
764/// @param DIE The designated initializer and its initialization
765/// expression.
766///
767/// @param DeclType The type of the "current object" (C99 6.7.8p17),
768/// into which the designation in @p DIE should refer.
769///
Douglas Gregor710f6d42009-01-22 23:26:18 +0000770/// @param NextField If non-NULL and the first designator in @p DIE is
771/// a field, this will be set to the field declaration corresponding
772/// to the field named by the designator.
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000773///
Douglas Gregor710f6d42009-01-22 23:26:18 +0000774/// @param NextElementIndex If non-NULL and the first designator in @p
775/// DIE is an array designator or GNU array-range designator, this
776/// will be set to the last index initialized by this designator.
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000777///
778/// @param Index Index into @p IList where the designated initializer
779/// @p DIE occurs.
780///
Douglas Gregorf603b472009-01-28 21:54:33 +0000781/// @param StructuredList The initializer list expression that
782/// describes all of the subobject initializers in the order they'll
783/// actually be initialized.
784///
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000785/// @returns true if there was an error, false otherwise.
Douglas Gregor710f6d42009-01-22 23:26:18 +0000786bool
787InitListChecker::CheckDesignatedInitializer(InitListExpr *IList,
788 DesignatedInitExpr *DIE,
789 DesignatedInitExpr::designators_iterator D,
790 QualType &CurrentObjectType,
791 RecordDecl::field_iterator *NextField,
792 llvm::APSInt *NextElementIndex,
Douglas Gregorf603b472009-01-28 21:54:33 +0000793 unsigned &Index,
794 InitListExpr *StructuredList,
Douglas Gregor36dd0c52009-01-28 23:36:17 +0000795 unsigned &StructuredIndex,
796 bool FinishSubobjectInit) {
Douglas Gregor710f6d42009-01-22 23:26:18 +0000797 if (D == DIE->designators_end()) {
798 // Check the actual initialization for the designated object type.
799 bool prevHadError = hadError;
Douglas Gregor36859eb2009-01-29 00:39:20 +0000800
801 // Temporarily remove the designator expression from the
802 // initializer list that the child calls see, so that we don't try
803 // to re-process the designator.
804 unsigned OldIndex = Index;
805 IList->setInit(OldIndex, DIE->getInit());
806
807 CheckSubElementType(IList, CurrentObjectType, Index,
Douglas Gregorf603b472009-01-28 21:54:33 +0000808 StructuredList, StructuredIndex);
Douglas Gregor36859eb2009-01-29 00:39:20 +0000809
810 // Restore the designated initializer expression in the syntactic
811 // form of the initializer list.
812 if (IList->getInit(OldIndex) != DIE->getInit())
813 DIE->setInit(IList->getInit(OldIndex));
814 IList->setInit(OldIndex, DIE);
815
Douglas Gregor710f6d42009-01-22 23:26:18 +0000816 return hadError && !prevHadError;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +0000817 }
818
Douglas Gregorf603b472009-01-28 21:54:33 +0000819 bool IsFirstDesignator = (D == DIE->designators_begin());
820 assert((IsFirstDesignator || StructuredList) &&
821 "Need a non-designated initializer list to start from");
822
823 // Determine the structural initializer list that corresponds to the
824 // current subobject.
825 StructuredList = IsFirstDesignator? SyntacticToSemantic[IList]
826 : getStructuredSubobjectInit(IList, Index, CurrentObjectType, StructuredList,
827 StructuredIndex,
828 SourceRange(D->getStartLocation(),
829 DIE->getSourceRange().getEnd()));
830 assert(StructuredList && "Expected a structured initializer list");
831
Douglas Gregor710f6d42009-01-22 23:26:18 +0000832 if (D->isFieldDesignator()) {
833 // C99 6.7.8p7:
834 //
835 // If a designator has the form
836 //
837 // . identifier
838 //
839 // then the current object (defined below) shall have
840 // structure or union type and the identifier shall be the
841 // name of a member of that type.
842 const RecordType *RT = CurrentObjectType->getAsRecordType();
843 if (!RT) {
844 SourceLocation Loc = D->getDotLoc();
845 if (Loc.isInvalid())
846 Loc = D->getFieldLoc();
847 SemaRef->Diag(Loc, diag::err_field_designator_non_aggr)
848 << SemaRef->getLangOptions().CPlusPlus << CurrentObjectType;
849 ++Index;
850 return true;
851 }
852
Douglas Gregorf603b472009-01-28 21:54:33 +0000853 // Note: we perform a linear search of the fields here, despite
854 // the fact that we have a faster lookup method, because we always
855 // need to compute the field's index.
Douglas Gregor710f6d42009-01-22 23:26:18 +0000856 IdentifierInfo *FieldName = D->getFieldName();
Douglas Gregorf603b472009-01-28 21:54:33 +0000857 unsigned FieldIndex = 0;
858 RecordDecl::field_iterator Field = RT->getDecl()->field_begin(),
859 FieldEnd = RT->getDecl()->field_end();
860 for (; Field != FieldEnd; ++Field) {
861 if (Field->isUnnamedBitfield())
862 continue;
863
864 if (Field->getIdentifier() == FieldName)
865 break;
866
867 ++FieldIndex;
Douglas Gregor710f6d42009-01-22 23:26:18 +0000868 }
869
Douglas Gregorf603b472009-01-28 21:54:33 +0000870 if (Field == FieldEnd) {
871 // We did not find the field we're looking for. Produce a
872 // suitable diagnostic and return a failure.
873 DeclContext::lookup_result Lookup = RT->getDecl()->lookup(FieldName);
874 if (Lookup.first == Lookup.second) {
875 // Name lookup didn't find anything.
876 SemaRef->Diag(D->getFieldLoc(), diag::err_field_designator_unknown)
877 << FieldName << CurrentObjectType;
878 } else {
879 // Name lookup found something, but it wasn't a field.
880 SemaRef->Diag(D->getFieldLoc(), diag::err_field_designator_nonfield)
881 << FieldName;
882 SemaRef->Diag((*Lookup.first)->getLocation(),
883 diag::note_field_designator_found);
884 }
885
886 ++Index;
887 return true;
888 } else if (cast<RecordDecl>((*Field)->getDeclContext())
889 ->isAnonymousStructOrUnion()) {
890 SemaRef->Diag(D->getFieldLoc(), diag::err_field_designator_anon_class)
891 << FieldName
892 << (cast<RecordDecl>((*Field)->getDeclContext())->isUnion()? 2 :
893 (int)SemaRef->getLangOptions().CPlusPlus);
894 SemaRef->Diag((*Field)->getLocation(), diag::note_field_designator_found);
Douglas Gregor710f6d42009-01-22 23:26:18 +0000895 ++Index;
896 return true;
897 }
Douglas Gregorf603b472009-01-28 21:54:33 +0000898
899 // All of the fields of a union are located at the same place in
900 // the initializer list.
Douglas Gregor82462762009-01-29 16:53:55 +0000901 if (RT->getDecl()->isUnion()) {
Douglas Gregorf603b472009-01-28 21:54:33 +0000902 FieldIndex = 0;
Douglas Gregor82462762009-01-29 16:53:55 +0000903 StructuredList->setInitializedFieldInUnion(*Field);
904 }
Douglas Gregorf603b472009-01-28 21:54:33 +0000905
Douglas Gregor710f6d42009-01-22 23:26:18 +0000906 // Update the designator with the field declaration.
Douglas Gregorf603b472009-01-28 21:54:33 +0000907 D->setField(*Field);
Douglas Gregor710f6d42009-01-22 23:26:18 +0000908
Douglas Gregorf603b472009-01-28 21:54:33 +0000909 // Make sure that our non-designated initializer list has space
910 // for a subobject corresponding to this field.
911 if (FieldIndex >= StructuredList->getNumInits())
912 StructuredList->resizeInits(SemaRef->Context, FieldIndex + 1);
913
Douglas Gregor710f6d42009-01-22 23:26:18 +0000914 // Recurse to check later designated subobjects.
Douglas Gregorf603b472009-01-28 21:54:33 +0000915 QualType FieldType = (*Field)->getType();
916 unsigned newStructuredIndex = FieldIndex;
917 if (CheckDesignatedInitializer(IList, DIE, ++D, FieldType, 0, 0, Index,
918 StructuredList, newStructuredIndex))
Douglas Gregor710f6d42009-01-22 23:26:18 +0000919 return true;
920
921 // Find the position of the next field to be initialized in this
922 // subobject.
Douglas Gregor710f6d42009-01-22 23:26:18 +0000923 ++Field;
Douglas Gregorf603b472009-01-28 21:54:33 +0000924 ++FieldIndex;
Douglas Gregor710f6d42009-01-22 23:26:18 +0000925
926 // If this the first designator, our caller will continue checking
927 // the rest of this struct/class/union subobject.
928 if (IsFirstDesignator) {
929 if (NextField)
930 *NextField = Field;
Douglas Gregorf603b472009-01-28 21:54:33 +0000931 StructuredIndex = FieldIndex;
Douglas Gregor710f6d42009-01-22 23:26:18 +0000932 return false;
933 }
934
Douglas Gregor36dd0c52009-01-28 23:36:17 +0000935 if (!FinishSubobjectInit)
936 return false;
937
Douglas Gregor710f6d42009-01-22 23:26:18 +0000938 // Check the remaining fields within this class/struct/union subobject.
939 bool prevHadError = hadError;
Douglas Gregorf603b472009-01-28 21:54:33 +0000940 CheckStructUnionTypes(IList, CurrentObjectType, Field, false, Index,
941 StructuredList, FieldIndex);
Douglas Gregor710f6d42009-01-22 23:26:18 +0000942 return hadError && !prevHadError;
943 }
944
945 // C99 6.7.8p6:
946 //
947 // If a designator has the form
948 //
949 // [ constant-expression ]
950 //
951 // then the current object (defined below) shall have array
952 // type and the expression shall be an integer constant
953 // expression. If the array is of unknown size, any
954 // nonnegative value is valid.
955 //
956 // Additionally, cope with the GNU extension that permits
957 // designators of the form
958 //
959 // [ constant-expression ... constant-expression ]
960 const ArrayType *AT = SemaRef->Context.getAsArrayType(CurrentObjectType);
961 if (!AT) {
962 SemaRef->Diag(D->getLBracketLoc(), diag::err_array_designator_non_array)
963 << CurrentObjectType;
964 ++Index;
965 return true;
966 }
967
968 Expr *IndexExpr = 0;
Douglas Gregor36dd0c52009-01-28 23:36:17 +0000969 llvm::APSInt DesignatedStartIndex, DesignatedEndIndex;
970 if (D->isArrayDesignator()) {
Douglas Gregor710f6d42009-01-22 23:26:18 +0000971 IndexExpr = DIE->getArrayIndex(*D);
Douglas Gregor36dd0c52009-01-28 23:36:17 +0000972
973 bool ConstExpr
974 = IndexExpr->isIntegerConstantExpr(DesignatedStartIndex, SemaRef->Context);
975 assert(ConstExpr && "Expression must be constant"); (void)ConstExpr;
976
977 DesignatedEndIndex = DesignatedStartIndex;
978 } else {
Douglas Gregor710f6d42009-01-22 23:26:18 +0000979 assert(D->isArrayRangeDesignator() && "Need array-range designator");
Douglas Gregor36dd0c52009-01-28 23:36:17 +0000980
981 bool StartConstExpr
982 = DIE->getArrayRangeStart(*D)->isIntegerConstantExpr(DesignatedStartIndex,
983 SemaRef->Context);
984 assert(StartConstExpr && "Expression must be constant"); (void)StartConstExpr;
985
986 bool EndConstExpr
987 = DIE->getArrayRangeEnd(*D)->isIntegerConstantExpr(DesignatedEndIndex,
988 SemaRef->Context);
989 assert(EndConstExpr && "Expression must be constant"); (void)EndConstExpr;
990
Douglas Gregor710f6d42009-01-22 23:26:18 +0000991 IndexExpr = DIE->getArrayRangeEnd(*D);
Douglas Gregor36dd0c52009-01-28 23:36:17 +0000992
993 if (DesignatedStartIndex.getZExtValue() != DesignatedEndIndex.getZExtValue())
Douglas Gregor9fddded2009-01-29 19:42:23 +0000994 FullyStructuredList->sawArrayRangeDesignator();
Douglas Gregor710f6d42009-01-22 23:26:18 +0000995 }
996
Douglas Gregor710f6d42009-01-22 23:26:18 +0000997 if (isa<ConstantArrayType>(AT)) {
998 llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(), false);
Douglas Gregor36dd0c52009-01-28 23:36:17 +0000999 DesignatedStartIndex.extOrTrunc(MaxElements.getBitWidth());
1000 DesignatedStartIndex.setIsUnsigned(MaxElements.isUnsigned());
1001 DesignatedEndIndex.extOrTrunc(MaxElements.getBitWidth());
1002 DesignatedEndIndex.setIsUnsigned(MaxElements.isUnsigned());
1003 if (DesignatedEndIndex >= MaxElements) {
Douglas Gregor710f6d42009-01-22 23:26:18 +00001004 SemaRef->Diag(IndexExpr->getSourceRange().getBegin(),
1005 diag::err_array_designator_too_large)
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001006 << DesignatedEndIndex.toString(10) << MaxElements.toString(10)
Douglas Gregor710f6d42009-01-22 23:26:18 +00001007 << IndexExpr->getSourceRange();
1008 ++Index;
1009 return true;
1010 }
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001011 } else {
1012 // Make sure the bit-widths and signedness match.
1013 if (DesignatedStartIndex.getBitWidth() > DesignatedEndIndex.getBitWidth())
1014 DesignatedEndIndex.extend(DesignatedStartIndex.getBitWidth());
1015 else if (DesignatedStartIndex.getBitWidth() < DesignatedEndIndex.getBitWidth())
1016 DesignatedStartIndex.extend(DesignatedEndIndex.getBitWidth());
1017 DesignatedStartIndex.setIsUnsigned(true);
1018 DesignatedEndIndex.setIsUnsigned(true);
Douglas Gregor710f6d42009-01-22 23:26:18 +00001019 }
1020
Douglas Gregorf603b472009-01-28 21:54:33 +00001021 // Make sure that our non-designated initializer list has space
1022 // for a subobject corresponding to this array element.
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001023 if (DesignatedEndIndex.getZExtValue() >= StructuredList->getNumInits())
1024 StructuredList->resizeInits(SemaRef->Context,
1025 DesignatedEndIndex.getZExtValue() + 1);
Douglas Gregorf603b472009-01-28 21:54:33 +00001026
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001027 // Repeatedly perform subobject initializations in the range
1028 // [DesignatedStartIndex, DesignatedEndIndex].
Douglas Gregor710f6d42009-01-22 23:26:18 +00001029
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001030 // Move to the next designator
1031 unsigned ElementIndex = DesignatedStartIndex.getZExtValue();
1032 unsigned OldIndex = Index;
1033 ++D;
1034 while (DesignatedStartIndex <= DesignatedEndIndex) {
1035 // Recurse to check later designated subobjects.
1036 QualType ElementType = AT->getElementType();
1037 Index = OldIndex;
1038 if (CheckDesignatedInitializer(IList, DIE, D, ElementType, 0, 0, Index,
1039 StructuredList, ElementIndex,
1040 (DesignatedStartIndex == DesignatedEndIndex)))
1041 return true;
1042
1043 // Move to the next index in the array that we'll be initializing.
1044 ++DesignatedStartIndex;
1045 ElementIndex = DesignatedStartIndex.getZExtValue();
1046 }
Douglas Gregor710f6d42009-01-22 23:26:18 +00001047
1048 // If this the first designator, our caller will continue checking
1049 // the rest of this array subobject.
1050 if (IsFirstDesignator) {
1051 if (NextElementIndex)
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001052 *NextElementIndex = DesignatedStartIndex;
Douglas Gregorf603b472009-01-28 21:54:33 +00001053 StructuredIndex = ElementIndex;
Douglas Gregor710f6d42009-01-22 23:26:18 +00001054 return false;
1055 }
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001056
1057 if (!FinishSubobjectInit)
1058 return false;
1059
Douglas Gregor710f6d42009-01-22 23:26:18 +00001060 // Check the remaining elements within this array subobject.
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001061 bool prevHadError = hadError;
Douglas Gregor36dd0c52009-01-28 23:36:17 +00001062 CheckArrayType(IList, CurrentObjectType, DesignatedStartIndex, true, Index,
Douglas Gregorf603b472009-01-28 21:54:33 +00001063 StructuredList, ElementIndex);
Douglas Gregor710f6d42009-01-22 23:26:18 +00001064 return hadError && !prevHadError;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001065}
1066
Douglas Gregorf603b472009-01-28 21:54:33 +00001067// Get the structured initializer list for a subobject of type
1068// @p CurrentObjectType.
1069InitListExpr *
1070InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
1071 QualType CurrentObjectType,
1072 InitListExpr *StructuredList,
1073 unsigned StructuredIndex,
1074 SourceRange InitRange) {
1075 Expr *ExistingInit = 0;
1076 if (!StructuredList)
1077 ExistingInit = SyntacticToSemantic[IList];
1078 else if (StructuredIndex < StructuredList->getNumInits())
1079 ExistingInit = StructuredList->getInit(StructuredIndex);
1080
1081 if (InitListExpr *Result = dyn_cast_or_null<InitListExpr>(ExistingInit))
1082 return Result;
1083
1084 if (ExistingInit) {
1085 // We are creating an initializer list that initializes the
1086 // subobjects of the current object, but there was already an
1087 // initialization that completely initialized the current
1088 // subobject, e.g., by a compound literal:
1089 //
1090 // struct X { int a, b; };
1091 // struct X xs[] = { [0] = (struct X) { 1, 2 }, [0].b = 3 };
1092 //
1093 // Here, xs[0].a == 0 and xs[0].b == 3, since the second,
1094 // designated initializer re-initializes the whole
1095 // subobject [0], overwriting previous initializers.
1096 SemaRef->Diag(InitRange.getBegin(), diag::warn_subobject_initializer_overrides)
1097 << InitRange;
1098 SemaRef->Diag(ExistingInit->getSourceRange().getBegin(),
1099 diag::note_previous_initializer)
Douglas Gregor756283b2009-01-28 23:43:32 +00001100 << /*FIXME:has side effects=*/0
Douglas Gregorf603b472009-01-28 21:54:33 +00001101 << ExistingInit->getSourceRange();
1102 }
1103
1104 InitListExpr *Result
1105 = new (SemaRef->Context) InitListExpr(SourceLocation(), 0, 0,
1106 SourceLocation());
1107 Result->setType(CurrentObjectType);
1108
1109 // Link this new initializer list into the structured initializer
1110 // lists.
1111 if (StructuredList)
1112 StructuredList->updateInit(StructuredIndex, Result);
1113 else {
1114 Result->setSyntacticForm(IList);
1115 SyntacticToSemantic[IList] = Result;
1116 }
1117
1118 return Result;
1119}
1120
1121/// Update the initializer at index @p StructuredIndex within the
1122/// structured initializer list to the value @p expr.
1123void InitListChecker::UpdateStructuredListElement(InitListExpr *StructuredList,
1124 unsigned &StructuredIndex,
1125 Expr *expr) {
1126 // No structured initializer list to update
1127 if (!StructuredList)
1128 return;
1129
1130 if (Expr *PrevInit = StructuredList->updateInit(StructuredIndex, expr)) {
1131 // This initializer overwrites a previous initializer. Warn.
1132 SemaRef->Diag(expr->getSourceRange().getBegin(),
1133 diag::warn_initializer_overrides)
1134 << expr->getSourceRange();
1135 SemaRef->Diag(PrevInit->getSourceRange().getBegin(),
1136 diag::note_previous_initializer)
Douglas Gregor756283b2009-01-28 23:43:32 +00001137 << /*FIXME:has side effects=*/0
Douglas Gregorf603b472009-01-28 21:54:33 +00001138 << PrevInit->getSourceRange();
1139 }
1140
1141 ++StructuredIndex;
1142}
1143
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001144/// Check that the given Index expression is a valid array designator
1145/// value. This is essentailly just a wrapper around
1146/// Expr::isIntegerConstantExpr that also checks for negative values
1147/// and produces a reasonable diagnostic if there is a
1148/// failure. Returns true if there was an error, false otherwise. If
1149/// everything went okay, Value will receive the value of the constant
1150/// expression.
1151static bool
1152CheckArrayDesignatorExpr(Sema &Self, Expr *Index, llvm::APSInt &Value) {
1153 SourceLocation Loc = Index->getSourceRange().getBegin();
1154
1155 // Make sure this is an integer constant expression.
1156 if (!Index->isIntegerConstantExpr(Value, Self.Context, &Loc))
1157 return Self.Diag(Loc, diag::err_array_designator_nonconstant)
1158 << Index->getSourceRange();
1159
1160 // Make sure this constant expression is non-negative.
Douglas Gregor69722702009-01-23 18:58:42 +00001161 llvm::APSInt Zero(llvm::APSInt::getNullValue(Value.getBitWidth()),
1162 Value.isUnsigned());
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001163 if (Value < Zero)
1164 return Self.Diag(Loc, diag::err_array_designator_negative)
1165 << Value.toString(10) << Index->getSourceRange();
1166
Douglas Gregore498e372009-01-23 21:04:18 +00001167 Value.setIsUnsigned(true);
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001168 return false;
1169}
1170
1171Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig,
1172 SourceLocation Loc,
1173 bool UsedColonSyntax,
1174 OwningExprResult Init) {
1175 typedef DesignatedInitExpr::Designator ASTDesignator;
1176
1177 bool Invalid = false;
1178 llvm::SmallVector<ASTDesignator, 32> Designators;
1179 llvm::SmallVector<Expr *, 32> InitExpressions;
1180
1181 // Build designators and check array designator expressions.
1182 for (unsigned Idx = 0; Idx < Desig.getNumDesignators(); ++Idx) {
1183 const Designator &D = Desig.getDesignator(Idx);
1184 switch (D.getKind()) {
1185 case Designator::FieldDesignator:
1186 Designators.push_back(ASTDesignator(D.getField(), D.getDotLoc(),
1187 D.getFieldLoc()));
1188 break;
1189
1190 case Designator::ArrayDesignator: {
1191 Expr *Index = static_cast<Expr *>(D.getArrayIndex());
1192 llvm::APSInt IndexValue;
1193 if (CheckArrayDesignatorExpr(*this, Index, IndexValue))
1194 Invalid = true;
1195 else {
1196 Designators.push_back(ASTDesignator(InitExpressions.size(),
1197 D.getLBracketLoc(),
1198 D.getRBracketLoc()));
1199 InitExpressions.push_back(Index);
1200 }
1201 break;
1202 }
1203
1204 case Designator::ArrayRangeDesignator: {
1205 Expr *StartIndex = static_cast<Expr *>(D.getArrayRangeStart());
1206 Expr *EndIndex = static_cast<Expr *>(D.getArrayRangeEnd());
1207 llvm::APSInt StartValue;
1208 llvm::APSInt EndValue;
1209 if (CheckArrayDesignatorExpr(*this, StartIndex, StartValue) ||
1210 CheckArrayDesignatorExpr(*this, EndIndex, EndValue))
1211 Invalid = true;
Douglas Gregorea0528d2009-01-23 22:22:29 +00001212 else {
1213 // Make sure we're comparing values with the same bit width.
1214 if (StartValue.getBitWidth() > EndValue.getBitWidth())
1215 EndValue.extend(StartValue.getBitWidth());
1216 else if (StartValue.getBitWidth() < EndValue.getBitWidth())
1217 StartValue.extend(EndValue.getBitWidth());
1218
1219 if (EndValue < StartValue) {
1220 Diag(D.getEllipsisLoc(), diag::err_array_designator_empty_range)
1221 << StartValue.toString(10) << EndValue.toString(10)
1222 << StartIndex->getSourceRange() << EndIndex->getSourceRange();
1223 Invalid = true;
1224 } else {
1225 Designators.push_back(ASTDesignator(InitExpressions.size(),
1226 D.getLBracketLoc(),
1227 D.getEllipsisLoc(),
1228 D.getRBracketLoc()));
1229 InitExpressions.push_back(StartIndex);
1230 InitExpressions.push_back(EndIndex);
1231 }
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001232 }
1233 break;
1234 }
1235 }
1236 }
1237
1238 if (Invalid || Init.isInvalid())
1239 return ExprError();
1240
1241 // Clear out the expressions within the designation.
1242 Desig.ClearExprs(*this);
1243
1244 DesignatedInitExpr *DIE
1245 = DesignatedInitExpr::Create(Context, &Designators[0], Designators.size(),
1246 &InitExpressions[0], InitExpressions.size(),
1247 Loc, UsedColonSyntax,
1248 static_cast<Expr *>(Init.release()));
1249 return Owned(DIE);
1250}
Douglas Gregor849afc32009-01-29 00:45:39 +00001251
1252bool Sema::CheckInitList(InitListExpr *&InitList, QualType &DeclType) {
1253 InitListChecker CheckInitList(this, InitList, DeclType);
1254 if (!CheckInitList.HadError())
1255 InitList = CheckInitList.getFullyStructuredList();
1256
1257 return CheckInitList.HadError();
1258}