From 2521dfa550805e3ca50c63eccbb185e6720a4041 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 17 May 2013 16:29:36 +0000 Subject: [PATCH] =?utf8?q?Objective-C++=20(and=20c++)=20Sema:=20Patch=20fi?= =?utf8?q?xes=20a=20sema=20crash=20when=20gnu=E2=80=99s=20=3F:=20extension?= =?utf8?q?=20is=20used=20for=20Objective-C++=E2=80=99s=20dictionary=20subs?= =?utf8?q?cripting.=20This=20is=20done=20by=20filtering=20out=20all=20plac?= =?utf8?q?eholder=20types=20before=20check=20on=20lowering=20of=20the=20co?= =?utf8?q?mmon=20expression=20is=20done.=20//=20rdar://1374918.=20Reviewed?= =?utf8?q?=20by=20John=20McCall.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182120 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 9 +++++++- test/SemaObjCXX/missing-lhs-gun-extension.mm | 23 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/SemaObjCXX/missing-lhs-gun-extension.mm diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 8c612b42ca..67c4f3e7dd 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/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/test/SemaObjCXX/missing-lhs-gun-extension.mm b/test/SemaObjCXX/missing-lhs-gun-extension.mm new file mode 100644 index 0000000000..0b5c998bd7 --- /dev/null +++ b/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; +} -- 2.40.0