Objective-C parsing [qoi]: Recover gracefully with good diagnostic

when class implementation declaration adds protocol qualifier
list. // rdar://12233858

llvm-svn: 180228
This commit is contained in:
Fariborz Jahanian 2013-04-24 23:23:47 +00:00
parent 2e87517144
commit 46ed4d978e
3 changed files with 30 additions and 0 deletions

View File

@ -413,6 +413,8 @@ def err_missing_catch_finally : Error<
def err_objc_concat_string : Error<"unexpected token after Objective-C string">;
def err_expected_objc_container : Error<
"'@end' must appear in an Objective-C context">;
def err_unexpected_protocol_qualifier : Error<
"@implementation declaration can not be protocol qualified">;
def err_objc_unexpected_atend : Error<
"'@end' appears where closing brace '}' is expected">;
def error_property_ivar_decl : Error<

View File

@ -1565,6 +1565,13 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) {
if (Tok.is(tok::l_brace)) // we have ivars
ParseObjCClassInstanceVariables(ObjCImpDecl, tok::objc_private, AtLoc);
else if (Tok.is(tok::less)) { // we have illegal '<' try to recover
Diag(Tok, diag::err_unexpected_protocol_qualifier);
// try to recover.
AttributeFactory attr;
DeclSpec DS(attr);
(void)ParseObjCProtocolQualifiers(DS);
}
}
assert(ObjCImpDecl);

View File

@ -0,0 +1,21 @@
// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
// rdar://12233858
@protocol P
@end
@interface I @end
@implementation I<P> @end // expected-error {{@implementation declaration can not be protocol qualified}}
@interface J < P,P >
@end
@implementation J < P,P > // expected-error {{@implementation declaration can not be protocol qualified}}
@end
@interface K @end
@implementation K <P // expected-error {{@implementation declaration can not be protocol qualified}}
@end // expected-error {{expected '>'}}