@@ -560,7 +560,10 @@ bool Parser::parseDecl(SmallVectorImpl<Decl*> &Entries, unsigned Flags) {
560
560
HadParseError = true ;
561
561
break ;
562
562
case tok::kw_union:
563
- HadParseError = parseDeclUnion (Flags, Entries);
563
+ if (Decl *D = parseDeclUnion (Flags).getPtrOrNull ())
564
+ Entries.push_back (D);
565
+ else
566
+ HadParseError = true ;
564
567
break ;
565
568
case tok::kw_case:
566
569
HadParseError = parseDeclUnionElement (Flags, Entries);
@@ -1645,7 +1648,7 @@ bool Parser::parseDeclFuncBodyDelayed(FuncDecl *FD) {
1645
1648
// / decl-union-body:
1646
1649
// / decl*
1647
1650
// /
1648
- bool Parser::parseDeclUnion (unsigned Flags, SmallVectorImpl<Decl*> &Decls ) {
1651
+ ParserResult<UnionDecl> Parser::parseDeclUnion (unsigned Flags) {
1649
1652
SourceLoc UnionLoc = consumeToken (tok::kw_union);
1650
1653
1651
1654
DeclAttributes Attributes;
@@ -1655,7 +1658,7 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
1655
1658
SourceLoc UnionNameLoc;
1656
1659
if (parseIdentifier (UnionName, UnionNameLoc,
1657
1660
diag::expected_identifier_in_decl, " union" ))
1658
- return true ;
1661
+ return nullptr ;
1659
1662
1660
1663
// Parse the generic-params, if present.
1661
1664
GenericParamList *GenericParams = nullptr ;
@@ -1669,7 +1672,6 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
1669
1672
UnionName, UnionNameLoc,
1670
1673
{ },
1671
1674
GenericParams, CurDeclContext);
1672
- Decls.push_back (UD);
1673
1675
1674
1676
// Now that we have a context, update the generic parameters with that
1675
1677
// context.
@@ -1691,7 +1693,7 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
1691
1693
SourceLoc LBLoc, RBLoc;
1692
1694
if (parseToken (tok::l_brace, LBLoc, diag::expected_lbrace_union_type)) {
1693
1695
UD->setMembers ({}, Tok.getLoc ());
1694
- return true ;
1696
+ return makeParserErrorResult (UD) ;
1695
1697
}
1696
1698
1697
1699
bool Invalid = false ;
@@ -1712,10 +1714,13 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
1712
1714
1713
1715
if (Flags & PD_DisallowNominalTypes) {
1714
1716
diagnose (UnionLoc, diag::disallowed_type);
1715
- return true ;
1717
+ return makeParserErrorResult (UD) ;
1716
1718
}
1717
-
1718
- return Invalid;
1719
+
1720
+ if (Invalid)
1721
+ return makeParserErrorResult (UD);
1722
+ else
1723
+ return makeParserResult (UD);
1719
1724
}
1720
1725
1721
1726
// / parseDeclUnionElement - Parse a 'case' of a union, returning true on error.
0 commit comments