Fix PR3001: if we have an error parsing an initializer, make sure to remove

the designator corresponding to it, otherwise Sema and later parsing will
get confused.

llvm-svn: 58603
This commit is contained in:
Chris Lattner 2008-11-03 09:28:22 +00:00
parent 7d7fff2303
commit 8cc7be369c
3 changed files with 28 additions and 2 deletions

View File

@ -221,6 +221,17 @@ public:
return 0;
}
/// EraseDesignation - If there is a designator for the specified initializer
/// index, remove it.
void EraseDesignation(unsigned Idx) {
Designation *D =const_cast<Designation*>(getDesignationForInitializer(Idx));
if (D == 0) return; // No designator.
D->FreeExprs(Actions);
unsigned SlotNo = D-&Designations[0];
Designations.erase(Designations.begin()+SlotNo);
}
};
} // end namespace clang

View File

@ -263,10 +263,18 @@ Parser::ExprResult Parser::ParseBraceInitializer() {
ExprResult SubElt;
if (!MayBeDesignationStart(Tok.getKind(), PP))
SubElt = ParseInitializer();
else
else {
SubElt = ParseInitializerWithPotentialDesignator(InitExprDesignations,
InitExprs.size());
// If we had an erroneous initializer, and we had a potentially valid
// designator, make sure to remove the designator from
// InitExprDesignations, otherwise we'll end up with a designator with no
// making initializer.
if (SubElt.isInvalid)
InitExprDesignations.EraseDesignation(InitExprs.size());
}
// If we couldn't parse the subelement, bail out.
if (!SubElt.isInvalid) {
InitExprs.push_back(SubElt.Val);

View File

@ -67,3 +67,10 @@ int sym_fw1a_scr[] = {
((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
};
// PR3001
struct s1 s2 = {
.a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}}
.b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
}