From: Douglas Gregor Date: Fri, 23 Sep 2011 19:19:41 +0000 (+0000) Subject: Clean up parsing the category names in interfaces slightly, using X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13d05ac08974ccb41f7da7595d769c158f58fbd6;p=clang Clean up parsing the category names in interfaces slightly, using MatchRHSPunctuation appropriately and giving a useful source location for the complaint about attributes being added to a category. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140404 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index a9c2a755f9..1d60062602 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -164,9 +164,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, SourceLocation nameLoc = ConsumeToken(); if (Tok.is(tok::l_paren) && !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. - // TODO(dgregor): Use the return value from the next line to provide better - // recovery. - ConsumeParen(); + SourceLocation LParenLoc = ConsumeParen(); SourceLocation categoryLoc, rparenLoc; IdentifierInfo *categoryId = 0; if (Tok.is(tok::code_completion)) { @@ -184,12 +182,16 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, Diag(Tok, diag::err_expected_ident); // missing category name. return 0; } - if (Tok.isNot(tok::r_paren)) { - Diag(Tok, diag::err_expected_rparen); - SkipUntil(tok::r_paren, false); // don't stop at ';' + + rparenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); + if (rparenLoc.isInvalid()) return 0; + + if (!attrs.empty()) { // categories don't support attributes. + Diag(nameLoc, diag::err_objc_no_attributes_on_category); + attrs.clear(); } - rparenLoc = ConsumeParen(); + // Next, we need to check for any protocol references. SourceLocation LAngleLoc, EndProtoLoc; SmallVector ProtocolRefs; @@ -199,9 +201,6 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, LAngleLoc, EndProtoLoc)) return 0; - if (!attrs.empty()) // categories don't support attributes. - Diag(Tok, diag::err_objc_no_attributes_on_category); - Decl *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, nameId, nameLoc, diff --git a/test/SemaObjC/attr-deprecated.m b/test/SemaObjC/attr-deprecated.m index d3d5f9537b..0152aca934 100644 --- a/test/SemaObjC/attr-deprecated.m +++ b/test/SemaObjC/attr-deprecated.m @@ -108,3 +108,7 @@ void test(Test2 *foo) { foo.test2 = x; // expected-warning {{'test2' is deprecated}} [foo setTest2: x]; // expected-warning {{'setTest2:' is deprecated}} } + +__attribute__((deprecated)) +@interface A(Blah) // expected-error{{attributes may not be specified on a category}} +@end