if (Tok.is(tok::kw_throw))
return ParseThrowExpression();
- ExprResult LHS = ParseCastExpression(false, false, ParsedType());
+ ExprResult LHS = ParseCastExpression(/*isUnaryExpression=*/false);
return ParseRHSOfBinaryExpression(move(LHS), prec::Assignment);
}
///
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
bool isAddressOfOperand,
- ParsedType TypeOfCast) {
+ bool isTypeCast) {
bool NotCastExpr;
ExprResult Res = ParseCastExpression(isUnaryExpression,
isAddressOfOperand,
NotCastExpr,
- TypeOfCast);
+ isTypeCast);
if (NotCastExpr)
Diag(Tok, diag::err_expected_expression);
return move(Res);
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
bool isAddressOfOperand,
bool &NotCastExpr,
- ParsedType TypeOfCast) {
+ bool isTypeCast) {
ExprResult Res;
tok::TokenKind SavedKind = Tok.getKind();
NotCastExpr = false;
ColonProtectionRAIIObject X(*this, false);
Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
- TypeOfCast, CastTy, RParenLoc);
+ isTypeCast, CastTy, RParenLoc);
}
switch (ParenExprType) {
return ExprError();
if (!Tok.is(tok::annot_cxxscope))
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
- NotCastExpr, TypeOfCast);
+ NotCastExpr, isTypeCast);
Token Next = NextToken();
if (Next.is(tok::annot_template_id)) {
ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false);
AnnotateTemplateIdTokenAsType();
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
- NotCastExpr, TypeOfCast);
+ NotCastExpr, isTypeCast);
}
}
// expression.
AnnotateTemplateIdTokenAsType();
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
- NotCastExpr, TypeOfCast);
+ NotCastExpr, isTypeCast);
}
// Fall through to treat the template-id as an id-expression.
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression);
ConsumeCodeCompletionToken();
return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
- NotCastExpr, TypeOfCast);
+ NotCastExpr, isTypeCast);
case tok::l_square:
// These can be followed by postfix-expr pieces.
if (getLang().ObjC1)
EnterExpressionEvaluationContext Unevaluated(Actions,
Sema::Unevaluated);
Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/,
- ParsedType(), CastTy, RParenLoc);
+ false, CastTy, RParenLoc);
CastRange = SourceRange(LParenLoc, RParenLoc);
// If ParseParenExpression parsed a '(typename)' sequence only, then this is
/// (__bridge_retained type-name) cast-expression
ExprResult
Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
- ParsedType TypeOfCast, ParsedType &CastTy,
+ bool isTypeCast, ParsedType &CastTy,
SourceLocation &RParenLoc) {
assert(Tok.is(tok::l_paren) && "Not a paren expr!");
GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);
TypeResult Ty = ParseTypeName();
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, OpenLoc);
- ExprResult SubExpr = ParseCastExpression(false, false, ParsedType());
+ ExprResult SubExpr = ParseCastExpression(/*isUnaryExpression=*/false);
if (Ty.isInvalid() || SubExpr.isInvalid())
return ExprError();
return ParseCXXAmbiguousParenExpression(ExprType, CastTy,
OpenLoc, RParenLoc);
- TypeResult Ty;
-
- {
- InMessageExpressionRAIIObject InMessage(*this, false);
- Ty = ParseTypeName();
- }
+ // Parse the type declarator.
+ DeclSpec DS(AttrFactory);
+ ParseSpecifierQualifierList(DS);
+ Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
+ ParseDeclarator(DeclaratorInfo);
// If our type is followed by an identifier and either ':' or ']', then
// this is probably an Objective-C message send where the leading '[' is
// missing. Recover as if that were the case.
- if (!Ty.isInvalid() && Tok.is(tok::identifier) && !InMessageExpression &&
- getLang().ObjC1 && !Ty.get().get().isNull() &&
- (NextToken().is(tok::colon) || NextToken().is(tok::r_square)) &&
- Ty.get().get()->isObjCObjectOrInterfaceType()) {
+ if (!DeclaratorInfo.isInvalidType() && Tok.is(tok::identifier) &&
+ !InMessageExpression && getLang().ObjC1 &&
+ (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) {
+ TypeResult Ty;
+ {
+ InMessageExpressionRAIIObject InMessage(*this, false);
+ Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+ }
Result = ParseObjCMessageExpressionBody(SourceLocation(),
SourceLocation(),
Ty.get(), 0);
if (Tok.is(tok::l_brace)) {
ExprType = CompoundLiteral;
+ TypeResult Ty;
+ {
+ InMessageExpressionRAIIObject InMessage(*this, false);
+ Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+ }
return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc);
}
if (ExprType == CastExpr) {
// We parsed '(' type-name ')' and the thing after it wasn't a '{'.
- if (Ty.isInvalid())
+ if (DeclaratorInfo.isInvalidType())
return ExprError();
- CastTy = Ty.get();
-
// Note that this doesn't parse the subsequent cast-expression, it just
// returns the parsed type to the callee.
- if (stopIfCastExpr)
+ if (stopIfCastExpr) {
+ TypeResult Ty;
+ {
+ InMessageExpressionRAIIObject InMessage(*this, false);
+ Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+ }
+ CastTy = Ty.get();
return ExprResult();
+ }
// Reject the cast of super idiom in ObjC.
if (Tok.is(tok::identifier) && getLang().ObjC1 &&
// Parse the cast-expression that follows it next.
// TODO: For cast expression with CastTy.
- Result = ParseCastExpression(false, false, CastTy);
- if (!Result.isInvalid())
- Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc, CastTy,
+ Result = ParseCastExpression(/*isUnaryExpression=*/false,
+ /*isAddressOfOperand=*/false,
+ /*isTypeCast=*/true);
+ if (!Result.isInvalid()) {
+ Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
+ DeclaratorInfo, CastTy,
RParenLoc, Result.take());
+ }
return move(Result);
}
Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
return ExprError();
}
- } else if (TypeOfCast) {
+ } else if (isTypeCast) {
// Parse the expression-list.
InMessageExpressionRAIIObject InMessage(*this, false);
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
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))
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);
}
-// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -verify -fblocks %s
void * cvt(id arg)
{
(void)(int*)arg; // expected-error {{cast of an Objective-C pointer to 'int *' is disallowed with ARC}}
(void)(id)arg;
(void)(__autoreleasing id*)arg; // expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}}
- (void)(id*)arg; // expected-error {{pointer to non-const type 'id' with no explicit ownership}} expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}}
+ (void)(id*)arg; // expected-error {{cast of an Objective-C pointer to '__strong id *' is disallowed with ARC}}
(void)(__autoreleasing id**)voidp_val;
(void)(void*)voidp_val;
aip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__autoreleasing id *' is disallowed with ARC}}
uip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC}}
}
+
+typedef void (^Block)();
+typedef void (^Block_strong)() __strong;
+typedef void (^Block_autoreleasing)() __autoreleasing;
+
+@class NSString;
+
+void ownership_transfer_in_cast(void *vp, Block *pblk) {
+ __strong NSString **sip = (NSString**)(__strong id *)vp;
+ __weak NSString **wip = (NSString**)(__weak id *)vp;
+ __autoreleasing id *aip = (id*)(__autoreleasing id *)vp;
+ __unsafe_unretained id *uip = (id*)(__unsafe_unretained id *)vp;
+
+ __strong id **sipp = (id**)(__strong id **)vp;
+ __weak id **wipp = (id**)(__weak id **)vp;
+ __autoreleasing id **aipp = (id**)(__autoreleasing id **)vp;
+ __unsafe_unretained id **uipp = (id**)(__unsafe_unretained id **)vp;
+
+ Block_strong blk_strong1;
+ Block_strong blk_strong2 = (Block)blk_strong1;
+ Block_autoreleasing *blk_auto = (Block*)pblk;
+}