diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2013-05-17 16:29:36 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-05-17 16:29:36 +0000 |
| commit | 3caab6cf6d2569c2bd88c0217f79fef3cb7d41de (patch) | |
| tree | cf8c1a5ed195247505f4cb31e4930ea302b7581f | |
| parent | 3334ade8518294a41475e5408c1ac60b8b725436 (diff) | |
| download | bcm5719-llvm-3caab6cf6d2569c2bd88c0217f79fef3cb7d41de.tar.gz bcm5719-llvm-3caab6cf6d2569c2bd88c0217f79fef3cb7d41de.zip | |
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
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 9 | ||||
| -rw-r--r-- | clang/test/SemaObjCXX/missing-lhs-gun-extension.mm | 23 |
2 files changed, 31 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8c612b42ca0..67c4f3e7ddd 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 00000000000..0b5c998bd75 --- /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 <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; +} |

