From: Argyrios Kyrtzidis Date: Fri, 1 Jul 2011 22:22:40 +0000 (+0000) Subject: Introduce Declarator::ObjCCatchContext, this will result in correct error for 'auto... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17b6399f8461c5b7e1c6f367b0a0dde49f921240;p=clang Introduce Declarator::ObjCCatchContext, this will result in correct error for 'auto' in obj-c catch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134271 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/DeclSpec.h b/include/clang/Sema/DeclSpec.h index af958f16da..db811d06f2 100644 --- a/include/clang/Sema/DeclSpec.h +++ b/include/clang/Sema/DeclSpec.h @@ -1351,6 +1351,7 @@ public: TemplateParamContext,// Within a template parameter list. CXXNewContext, // C++ new-expression. CXXCatchContext, // C++ catch exception-declaration + ObjCCatchContext, // Objective-C catch exception-declaration BlockLiteralContext, // Block literal declarator. TemplateTypeArgContext, // Template type argument. AliasDeclContext, // C++0x alias-declaration. @@ -1502,6 +1503,7 @@ public: case TemplateParamContext: case CXXNewContext: case CXXCatchContext: + case ObjCCatchContext: case BlockLiteralContext: case TemplateTypeArgContext: return true; @@ -1523,6 +1525,7 @@ public: case PrototypeContext: case TemplateParamContext: case CXXCatchContext: + case ObjCCatchContext: return true; case TypeNameContext: @@ -1555,6 +1558,7 @@ public: case ObjCPrototypeContext: case TemplateParamContext: case CXXCatchContext: + case ObjCCatchContext: case TypeNameContext: case CXXNewContext: case AliasDeclContext: diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 8a6c964214..7641565d1c 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1633,10 +1633,7 @@ StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { if (Tok.isNot(tok::ellipsis)) { DeclSpec DS(AttrFactory); ParseDeclarationSpecifiers(DS); - // For some odd reason, the name of the exception variable is - // optional. As a result, we need to use "PrototypeContext", because - // we must accept either 'declarator' or 'abstract-declarator' here. - Declarator ParmDecl(DS, Declarator::PrototypeContext); + Declarator ParmDecl(DS, Declarator::ObjCCatchContext); ParseDeclarator(ParmDecl); // Inform the actions module about the declarator, so it diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index fa18a32aaa..2254821cb1 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -1803,6 +1803,7 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { } break; case Declarator::CXXCatchContext: + case Declarator::ObjCCatchContext: Error = 4; // Exception declaration break; case Declarator::TemplateParamContext: @@ -2441,6 +2442,7 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { case Declarator::ForContext: case Declarator::ConditionContext: case Declarator::CXXCatchContext: + case Declarator::ObjCCatchContext: case Declarator::BlockLiteralContext: case Declarator::TemplateTypeArgContext: // FIXME: We may want to allow parameter packs in block-literal contexts @@ -2480,6 +2482,7 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { case Declarator::TemplateParamContext: case Declarator::CXXNewContext: case Declarator::CXXCatchContext: + case Declarator::ObjCCatchContext: case Declarator::TemplateTypeArgContext: Diag(OwnedTagDecl->getLocation(),diag::err_type_defined_in_type_specifier) << Context.getTypeDeclType(OwnedTagDecl); diff --git a/test/SemaObjCXX/arc-0x.mm b/test/SemaObjCXX/arc-0x.mm index 9b48da5a33..fa022af522 100644 --- a/test/SemaObjCXX/arc-0x.mm +++ b/test/SemaObjCXX/arc-0x.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++0x -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify -fblocks %s +// RUN: %clang_cc1 -std=c++0x -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify -fblocks -fobjc-exceptions %s // "Move" semantics, trivial version. void move_it(__strong id &&from) { @@ -25,4 +25,8 @@ void deduction(id obj) { for (auto x : array) { __strong id *xPtr = &x; } + + @try { + } @catch (auto e) { // expected-error {{'auto' not allowed in exception declaration}} + } }