diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4595,8 +4595,8 @@ << SourceRange(base->getBeginLoc(), rbLoc); return ExprError(); } - // If the base is either a MatrixSubscriptExpr or a matrix type, try to create - // a new MatrixSubscriptExpr. + // If the base is a MatrixSubscriptExpr, try to create a new + // MatrixSubscriptExpr. auto *matSubscriptE = dyn_cast(base); if (matSubscriptE) { if (CheckAndReportCommaError(idx)) @@ -4607,34 +4607,13 @@ return CreateBuiltinMatrixSubscriptExpr( matSubscriptE->getBase(), matSubscriptE->getRowIdx(), idx, rbLoc); } - Expr *matrixBase = base; - bool IsMSPropertySubscript = isMSPropertySubscriptExpr(*this, base); - if (!IsMSPropertySubscript) { - ExprResult result = CheckPlaceholderExpr(base); - if (!result.isInvalid()) - matrixBase = result.get(); - } - if (matrixBase->getType()->isMatrixType()) { - if (CheckAndReportCommaError(idx)) - return ExprError(); - - return CreateBuiltinMatrixSubscriptExpr(matrixBase, idx, nullptr, rbLoc); - } - - // A comma-expression as the index is deprecated in C++2a onwards. - if (getLangOpts().CPlusPlus20 && - ((isa(idx) && cast(idx)->isCommaOp()) || - (isa(idx) && - cast(idx)->getOperator() == OO_Comma))) { - Diag(idx->getExprLoc(), diag::warn_deprecated_comma_subscript) - << SourceRange(base->getBeginLoc(), rbLoc); - } // Handle any non-overload placeholder types in the base and index // expressions. We can't handle overloads here because the other // operand might be an overloadable type, in which case the overload // resolution for the operator overload should get the first crack // at the overload. + bool IsMSPropertySubscript = false; if (base->getType()->isNonOverloadPlaceholderType()) { IsMSPropertySubscript = isMSPropertySubscriptExpr(*this, base); if (!IsMSPropertySubscript) { @@ -4644,6 +4623,24 @@ base = result.get(); } } + + // If the base is a matrix type, try to create a new MatrixSubscriptExpr. + if (base->getType()->isMatrixType()) { + if (CheckAndReportCommaError(idx)) + return ExprError(); + + return CreateBuiltinMatrixSubscriptExpr(base, idx, nullptr, rbLoc); + } + + // A comma-expression as the index is deprecated in C++2a onwards. + if (getLangOpts().CPlusPlus20 && + ((isa(idx) && cast(idx)->isCommaOp()) || + (isa(idx) && + cast(idx)->getOperator() == OO_Comma))) { + Diag(idx->getExprLoc(), diag::warn_deprecated_comma_subscript) + << SourceRange(base->getBeginLoc(), rbLoc); + } + if (idx->getType()->isNonOverloadPlaceholderType()) { ExprResult result = CheckPlaceholderExpr(idx); if (result.isInvalid()) return ExprError(); diff --git a/clang/test/SemaObjC/arc-repeated-weak.mm b/clang/test/SemaObjC/arc-repeated-weak.mm --- a/clang/test/SemaObjC/arc-repeated-weak.mm +++ b/clang/test/SemaObjC/arc-repeated-weak.mm @@ -485,3 +485,17 @@ @class NSString; static NSString* const kGlobal = @""; + +@interface NSDictionary +- (id)objectForKeyedSubscript:(id)key; +@end + +@interface WeakProp +@property (weak) NSDictionary *nd; +@end + +@implementation WeakProp +-(void)m { + (void)self.nd[@""]; // no warning +} +@end