aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-06-03 05:36:54 +0000
committerSteve Naroff <snaroff@apple.com>2008-06-03 05:36:54 +0000
commit459a1e2212115f4ff89db7f444df5af41792b18a (patch)
tree49903083873585611d644827744af724d82d247a
parente3e9add4fd788927df6f545570e7838db59c01d7 (diff)
Fix parser bug/FIXME with @catch.
<rdar://problem/5980846> clang on xcode: error: declarator requires an identifier (for @catch) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51895 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Parse/ParseObjc.cpp18
-rw-r--r--test/Sema/objc-try-catch.m37
2 files changed, 48 insertions, 7 deletions
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 6a07503737..933a7a606c 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -1193,15 +1193,19 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
if (Tok.isNot(tok::ellipsis)) {
DeclSpec DS;
ParseDeclarationSpecifiers(DS);
- // FIXME: Is BlockContext right?
- Declarator DeclaratorInfo(DS, Declarator::BlockContext);
+ // For some odd reason, the name of the exception variable is
+ // optional. As a result, we need to use PrototypeContext.
+ Declarator DeclaratorInfo(DS, Declarator::PrototypeContext);
ParseDeclarator(DeclaratorInfo);
- DeclTy *aBlockVarDecl = Actions.ActOnDeclarator(CurScope,
+ if (DeclaratorInfo.getIdentifier()) {
+ DeclTy *aBlockVarDecl = Actions.ActOnDeclarator(CurScope,
DeclaratorInfo, 0);
- StmtResult stmtResult =
- Actions.ActOnDeclStmt(aBlockVarDecl, DS.getSourceRange().getBegin(),
- DeclaratorInfo.getSourceRange().getEnd());
- FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val;
+ StmtResult stmtResult =
+ Actions.ActOnDeclStmt(aBlockVarDecl,
+ DS.getSourceRange().getBegin(),
+ DeclaratorInfo.getSourceRange().getEnd());
+ FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val;
+ }
} else
ConsumeToken(); // consume '...'
SourceLocation RParenLoc = ConsumeParen();
diff --git a/test/Sema/objc-try-catch.m b/test/Sema/objc-try-catch.m
new file mode 100644
index 0000000000..e4c20b7343
--- /dev/null
+++ b/test/Sema/objc-try-catch.m
@@ -0,0 +1,37 @@
+// RUN: clang -fsyntax-only -verify %s
+typedef signed char BOOL;
+typedef struct _NSZone NSZone;
+
+@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+
+@protocol NSObject
+- (BOOL)isEqual:(id)object;
+@end
+
+@protocol NSCopying
+- (id)copyWithZone:(NSZone *)zone;
+@end
+
+@protocol NSCoding
+- (void)encodeWithCoder:(NSCoder *)aCoder;
+@end
+
+@interface NSObject <NSObject> {}
+@end
+
+@class NSData, NSArray, NSDictionary, NSCharacterSet, NSData, NSURL, NSError, NSLocale;
+
+@interface NSException : NSObject <NSCopying, NSCoding> {}
+@end
+
+@class ASTNode, XCRefactoringParser, Transform, TransformInstance, XCRefactoringSelectionInfo;
+
+@interface XCRefactoringTransformation : NSObject {}
+@end
+
+@implementation XCRefactoringTransformation
+- (NSDictionary *)setUpInfoForTransformKey:(NSString *)transformKey outError:(NSError **)outError; {
+ @try {}
+ // the exception name is optional (weird)
+ @catch (NSException *) {}
+}