From 3caab6cf6d2569c2bd88c0217f79fef3cb7d41de Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 17 May 2013 16:29:36 +0000 Subject: [PATCH] =?UTF-8?q?Objective-C++=20(and=20c++)=20Sema:=20Patch=20f?= =?UTF-8?q?ixes=20a=20sema=20crash=20when=20gnu=E2=80=99s=20=3F:=20extensi?= =?UTF-8?q?on=20is=20used=20for=20Objective-C++=E2=80=99s=20dictionary=20s?= =?UTF-8?q?ubscripting.=20This=20is=20done=20by=20filtering=20out=20all=20?= =?UTF-8?q?placeholder=20types=20before=20check=20on=20lowering=20of=20the?= =?UTF-8?q?=20common=20expression=20is=20done.=20//=20rdar://1374918.=20Re?= =?UTF-8?q?viewed=20by=20John=20McCall.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit llvm-svn: 182120 --- clang/lib/Sema/SemaExpr.cpp | 9 +++++++- .../SemaObjCXX/missing-lhs-gun-extension.mm | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaObjCXX/missing-lhs-gun-extension.mm diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8c612b42ca02..67c4f3e7dddd 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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 diff --git a/clang/test/SemaObjCXX/missing-lhs-gun-extension.mm b/clang/test/SemaObjCXX/missing-lhs-gun-extension.mm new file mode 100644 index 000000000000..0b5c998bd755 --- /dev/null +++ b/clang/test/SemaObjCXX/missing-lhs-gun-extension.mm @@ -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 T tfoo(U x) { return x; } + +void func() { + NSDictionary* foo; + NSString* result = foo[@"bar"] ? : foo[@"baz"]; + + int (*fn)(int) = (&tfoo ?: 0); + + int x = 0; + const int &y = foo.random ?: x; +}