[ARC] When casting from a pointer to an objective-c object with known ownership, if the
cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
to the cast type:
id x;
(NSString**)&x; // Casting as (__strong NSString**).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134275 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index 6324992..6822681 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -2200,7 +2200,8 @@
Result = ParseCastExpression(false/*isUnaryExpression*/,
false/*isAddressofOperand*/,
NotCastExpr,
- ParsedType()/*TypeOfCast*/);
+ // type-id has priority.
+ true/*isTypeCast*/);
}
// If we parsed a cast-expression, it's really a type-id, otherwise it's
@@ -2219,7 +2220,11 @@
ConsumeAnyToken();
if (ParseAs >= CompoundLiteral) {
- TypeResult Ty = ParseTypeName();
+ // Parse the type declarator.
+ DeclSpec DS(AttrFactory);
+ ParseSpecifierQualifierList(DS);
+ Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
+ ParseDeclarator(DeclaratorInfo);
// Match the ')'.
if (Tok.is(tok::r_paren))
@@ -2229,21 +2234,21 @@
if (ParseAs == CompoundLiteral) {
ExprType = CompoundLiteral;
+ TypeResult Ty = ParseTypeName();
return ParseCompoundLiteralExpression(Ty.get(), LParenLoc, RParenLoc);
}
// We parsed '(' type-id ')' and the thing after it wasn't a '{'.
assert(ParseAs == CastExpr);
- if (Ty.isInvalid())
+ if (DeclaratorInfo.isInvalidType())
return ExprError();
- CastTy = Ty.get();
-
// Result is what ParseCastExpression returned earlier.
if (!Result.isInvalid())
- Result = Actions.ActOnCastExpr(getCurScope(), LParenLoc, CastTy, RParenLoc,
- Result.take());
+ Result = Actions.ActOnCastExpr(getCurScope(), LParenLoc,
+ DeclaratorInfo, CastTy,
+ RParenLoc, Result.take());
return move(Result);
}