diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 4d9d42d258e5..e477ef53ab8a 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -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< diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 23afa4ff3de5..aa9c05ec7fc2 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -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); diff --git a/clang/test/Parser/objc-error-qualified-implementation.m b/clang/test/Parser/objc-error-qualified-implementation.m new file mode 100644 index 000000000000..444fb5dab44c --- /dev/null +++ b/clang/test/Parser/objc-error-qualified-implementation.m @@ -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

@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

'}}