Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Sema/SemaInit.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 1,302 Lines • ▼ Show 20 Lines | CheckStructUnionTypes(Entity, IList, DeclType, Bases, RD->field_begin(), | ||||
StructuredIndex, TopLevelObject); | StructuredIndex, TopLevelObject); | ||||
} else if (DeclType->isArrayType()) { | } else if (DeclType->isArrayType()) { | ||||
llvm::APSInt Zero( | llvm::APSInt Zero( | ||||
SemaRef.Context.getTypeSize(SemaRef.Context.getSizeType()), | SemaRef.Context.getTypeSize(SemaRef.Context.getSizeType()), | ||||
false); | false); | ||||
CheckArrayType(Entity, IList, DeclType, Zero, | CheckArrayType(Entity, IList, DeclType, Zero, | ||||
SubobjectIsDesignatorContext, Index, | SubobjectIsDesignatorContext, Index, | ||||
StructuredList, StructuredIndex); | StructuredList, StructuredIndex); | ||||
} else if (DeclType->isVoidType() || DeclType->isFunctionType()) { | } else if (DeclType->isVoidType()) { | ||||
// [expr.type.conv]p2: Otherwise, if the type is cv void and the | |||||
// initializer is () or {} (after pack expansion, if any), the expression | |||||
// is a prvalue of type void that performs no initialization. | |||||
if (IList->getNumInits() > 0) { | |||||
if (!VerifyOnly) | |||||
SemaRef.Diag(IList->getBeginLoc(), diag::err_init_list_void_nonempty); | |||||
hadError = true; | |||||
} | |||||
rsmith: Hm, this seems like the wrong place for this check, given the wording -- the language rule is… | |||||
} else if (DeclType->isFunctionType()) { | |||||
// This type is invalid, issue a diagnostic. | // This type is invalid, issue a diagnostic. | ||||
++Index; | ++Index; | ||||
if (!VerifyOnly) | if (!VerifyOnly) | ||||
SemaRef.Diag(IList->getBeginLoc(), diag::err_illegal_initializer_type) | SemaRef.Diag(IList->getBeginLoc(), diag::err_illegal_initializer_type) | ||||
<< DeclType; | << DeclType; | ||||
hadError = true; | hadError = true; | ||||
} else if (DeclType->isReferenceType()) { | } else if (DeclType->isReferenceType()) { | ||||
CheckReferenceType(Entity, IList, DeclType, Index, | CheckReferenceType(Entity, IList, DeclType, Index, | ||||
▲ Show 20 Lines • Show All 8,910 Lines • Show Last 20 Lines |
Hm, this seems like the wrong place for this check, given the wording -- the language rule is specific to functional casts, and shouldn't apply to initialization of void-typed objects in general -- but perhaps it's the best place we have (and I think we deal with the void() case here in SemaInit too). Please at least make sure that we still properly reject things like:
We also need to decide whether to accept the compound-literal form of this:
GCC trunk does, but I'm not sure whether that's intentional or an oversight. We certainly shouldn't accept that (without a diagnostic, at least) in C.