Update Parser::ParseTypeName to return a TypeResult, which also tells
us whether there was an error in trying to parse a type-name (type-id
in C++). This allows propagation of errors further in the compiler,
suppressing more bogus error messages.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64922 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index e8ef8ea..fb60bde 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -211,7 +211,7 @@
if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
return ExprError();
- TypeTy *CastTy = ParseTypeName();
+ TypeResult CastTy = ParseTypeName();
SourceLocation RAngleBracketLoc = Tok.getLocation();
if (ExpectAndConsume(tok::greater, diag::err_expected_greater))
@@ -224,9 +224,10 @@
OwningExprResult Result(ParseSimpleParenExpression(RParenLoc));
- if (!Result.isInvalid())
+ if (!Result.isInvalid() && !CastTy.isInvalid())
Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
- LAngleBracketLoc, CastTy, RAngleBracketLoc,
+ LAngleBracketLoc, CastTy.get(),
+ RAngleBracketLoc,
LParenLoc, Result.release(), RParenLoc);
return move(Result);
@@ -253,16 +254,16 @@
OwningExprResult Result(Actions);
if (isTypeIdInParens()) {
- TypeTy *Ty = ParseTypeName();
+ TypeResult Ty = ParseTypeName();
// Match the ')'.
MatchRHSPunctuation(tok::r_paren, LParenLoc);
- if (!Ty)
+ if (Ty.isInvalid())
return ExprError();
Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true,
- Ty, RParenLoc);
+ Ty.get(), RParenLoc);
} else {
Result = ParseExpression();
@@ -919,9 +920,12 @@
// FIXME: Error reporting absolutely sucks! If the this fails to parse a type
// there will be cryptic errors about mismatched parentheses and missing
// specifiers.
- TypeTy *Ty = ParseTypeName();
+ TypeResult Ty = ParseTypeName();
SourceLocation RParen = MatchRHSPunctuation(tok::r_paren, LParen);
- return Actions.ActOnUnaryTypeTrait(UTT, Loc, LParen, Ty, RParen);
+ if (Ty.isInvalid())
+ return ExprError();
+
+ return Actions.ActOnUnaryTypeTrait(UTT, Loc, LParen, Ty.get(), RParen);
}