r191155 - ObjectiveC: ObjC declarations, including forward class

Fariborz Jahanian fjahanian at apple.com
Sat Sep 21 17:02:16 PDT 2013


Author: fjahanian
Date: Sat Sep 21 19:02:16 2013
New Revision: 191155

URL: http://llvm.org/viewvc/llvm-project?rev=191155&view=rev
Log:
ObjectiveC: ObjC declarations, including forward class
and protocols can be at global scope only.

Modified:
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/Parser/missing-end-4.m

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=191155&r1=191154&r2=191155&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sat Sep 21 19:02:16 2013
@@ -809,6 +809,12 @@ Sema::ActOnForwardProtocolDeclaration(So
                                       unsigned NumElts,
                                       AttributeList *attrList) {
   SmallVector<Decl *, 8> DeclsInGroup;
+  if (isa<ObjCContainerDecl>(CurContext)) {
+    Diag(AtProtocolLoc, 
+         diag::err_objc_decls_may_only_appear_in_global_scope);
+    return BuildDeclaratorGroup(DeclsInGroup, false);
+  }
+
   for (unsigned i = 0; i != NumElts; ++i) {
     IdentifierInfo *Ident = IdentList[i].first;
     ObjCProtocolDecl *PrevDecl = LookupProtocol(Ident, IdentList[i].second,
@@ -1927,6 +1933,12 @@ Sema::ActOnForwardClassDeclaration(Sourc
                                    SourceLocation *IdentLocs,
                                    unsigned NumElts) {
   SmallVector<Decl *, 8> DeclsInGroup;
+  if (isa<ObjCContainerDecl>(CurContext)) {
+    Diag(AtClassLoc, 
+         diag::err_objc_decls_may_only_appear_in_global_scope);
+    return BuildDeclaratorGroup(DeclsInGroup, false);
+  }
+
   for (unsigned i = 0; i != NumElts; ++i) {
     // Check for another declaration kind with the same name.
     NamedDecl *PrevDecl

Modified: cfe/trunk/test/Parser/missing-end-4.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/missing-end-4.m?rev=191155&r1=191154&r2=191155&view=diff
==============================================================================
--- cfe/trunk/test/Parser/missing-end-4.m (original)
+++ cfe/trunk/test/Parser/missing-end-4.m Sat Sep 21 19:02:16 2013
@@ -32,9 +32,9 @@
 @interface I
 @end
 @implementation I
- at protocol P; // forward declarations of protocols in @implementations is allowed
- at class C; // forward declarations of classes in @implementations is allowed
-- (C<P>*) MyMeth {}
+ at protocol P; // expected-error {{Objective-C declarations may only appear in global scope}}
+ at class C; // expected-error {{Objective-C declarations may only appear in global scope}}
+- (C<P>*) MyMeth {} // expected-error {{expected a type}}
 @end
 
 @interface I2 {}
@@ -47,5 +47,5 @@
 @implementation I3
 - Meth {}
 + Cls {}
- at protocol P3;
+ at protocol P3; // expected-error {{Objective-C declarations may only appear in global scope}}
 @end





More information about the cfe-commits mailing list