]> granicus.if.org Git - clang/commitdiff
Objective-C parsing [qoi]: Recover gracefully with good diagnostic
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 24 Apr 2013 23:23:47 +0000 (23:23 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 24 Apr 2013 23:23:47 +0000 (23:23 +0000)
when class implementation declaration adds protocol qualifier
list. // rdar://12233858

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180228 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseObjc.cpp
test/Parser/objc-error-qualified-implementation.m [new file with mode: 0644]

index 4d9d42d258e5dcca890a5264b748b6a34dbdb793..e477ef53ab8ad16c6ef4d283f5c8cf8ac75fe900 100644 (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<
index 23afa4ff3de5fb287767129c463cb494fb65be45..aa9c05ec7fc290b532919073ffcdbc5cb4ad289e 100644 (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);
 
diff --git a/test/Parser/objc-error-qualified-implementation.m b/test/Parser/objc-error-qualified-implementation.m
new file mode 100644 (file)
index 0000000..444fb5d
--- /dev/null
@@ -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 '>'}}