Objective-C++ (and c++) Sema: Patch fixes a sema crash when gnu’s ?: extension

is used for Objective-C++’s dictionary subscripting. This is done by filtering
out all placeholder types before check on lowering of the
common expression is done. // rdar://1374918.
Reviewed by John McCall.

llvm-svn: 182120
This commit is contained in:
Fariborz Jahanian 2013-05-17 16:29:36 +00:00
parent 3334ade851
commit 3caab6cf6d
2 changed files with 31 additions and 1 deletions

View File

@ -5630,7 +5630,14 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
Expr *commonExpr = 0;
if (LHSExpr == 0) {
commonExpr = CondExpr;
// Lower out placeholder types first. This is important so that we don't
// try to capture a placeholder. This happens in few cases in C++; such
// as Objective-C++'s dictionary subscripting syntax.
if (commonExpr->hasPlaceholderType()) {
ExprResult result = CheckPlaceholderExpr(commonExpr);
if (!result.isUsable()) return ExprError();
commonExpr = result.take();
}
// We usually want to apply unary conversions *before* saving, except
// in the special case of a C++ l-value conditional.
if (!(getLangOpts().CPlusPlus

View File

@ -0,0 +1,23 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// expected-no-diagnostics
// rdar://13749180
@interface NSDictionary
- (id)objectForKeyedSubscript:(id)key;
- (void)setObject:(id)object forKeyedSubscript:(id)key;
- (int &) random;
@end
@class NSString;
template <class T, class U = T> T tfoo(U x) { return x; }
void func() {
NSDictionary* foo;
NSString* result = foo[@"bar"] ? : foo[@"baz"];
int (*fn)(int) = (&tfoo<int> ?: 0);
int x = 0;
const int &y = foo.random ?: x;
}