Changeset View
Changeset View
Standalone View
Standalone View
lib/Sema/SemaInit.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
if (RT->getDecl()->isUnion()) { | if (RT->getDecl()->isUnion()) { | ||||
FieldIndex = 0; | FieldIndex = 0; | ||||
if (!VerifyOnly) { | if (!VerifyOnly) { | ||||
FieldDecl *CurrentField = StructuredList->getInitializedFieldInUnion(); | FieldDecl *CurrentField = StructuredList->getInitializedFieldInUnion(); | ||||
if (CurrentField && !declaresSameEntity(CurrentField, *Field)) { | if (CurrentField && !declaresSameEntity(CurrentField, *Field)) { | ||||
assert(StructuredList->getNumInits() == 1 | assert(StructuredList->getNumInits() == 1 | ||||
&& "A union should never have more than one initializer!"); | && "A union should never have more than one initializer!"); | ||||
// We're about to throw away an initializer, emit warning. | |||||
SemaRef.Diag(D->getFieldLoc(), | |||||
diag::warn_initializer_overrides) | |||||
<< D->getSourceRange(); | |||||
Expr *ExistingInit = StructuredList->getInit(0); | Expr *ExistingInit = StructuredList->getInit(0); | ||||
SemaRef.Diag(ExistingInit->getLocStart(), | if (ExistingInit) { | ||||
diag::note_previous_initializer) | // We're about to throw away an initializer, emit warning. | ||||
<< /*FIXME:has side effects=*/0 | SemaRef.Diag(D->getFieldLoc(), | ||||
<< ExistingInit->getSourceRange(); | diag::warn_initializer_overrides) | ||||
<< D->getSourceRange(); | |||||
SemaRef.Diag(ExistingInit->getLocStart(), | |||||
diag::note_previous_initializer) | |||||
<< /*FIXME:has side effects=*/0 | |||||
<< ExistingInit->getSourceRange(); | |||||
} | |||||
// remove existing initializer | // remove existing initializer | ||||
StructuredList->resizeInits(SemaRef.Context, 0); | StructuredList->resizeInits(SemaRef.Context, 0); | ||||
StructuredList->setInitializedFieldInUnion(nullptr); | StructuredList->setInitializedFieldInUnion(nullptr); | ||||
} | } | ||||
StructuredList->setInitializedFieldInUnion(*Field); | StructuredList->setInitializedFieldInUnion(*Field); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |