Attempting to initialize a union member that does not exist no longer crashes.

Patch by Remi Gacogne

llvm-svn: 150144
This commit is contained in:
Aaron Ballman 2012-02-09 03:29:06 +00:00
parent 8a54a40a44
commit 3bc84198f4
2 changed files with 14 additions and 4 deletions

View File

@ -1511,7 +1511,8 @@ static IndirectFieldDecl *FindIndirectFieldDesignator(FieldDecl *AnonField,
IdentifierInfo *FieldName) {
assert(AnonField->isAnonymousStructOrUnion());
Decl *NextDecl = AnonField->getNextDeclInContext();
while (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(NextDecl)) {
IndirectFieldDecl *IF = NULL;
while (NextDecl && (IF = dyn_cast<IndirectFieldDecl>(NextDecl))) {
if (FieldName && FieldName == IF->getAnonField()->getIdentifier())
return IF;
NextDecl = NextDecl->getNextDeclInContext();

View File

@ -18,10 +18,19 @@ extern int x;
void *g = &x;
int *h = &x;
struct union_crash
{
union
{
};
};
int test() {
int a[10];
int b[10] = a; // expected-error {{array initializer must be an initializer list}}
int +; // expected-error {{expected identifier or '('}}
int a[10];
int b[10] = a; // expected-error {{array initializer must be an initializer list}}
int +; // expected-error {{expected identifier or '('}}
struct union_crash u = { .d = 1 }; // expected-error {{field designator 'd' does not refer to any field in type 'struct union_crash'}}
}