void RewriteModernObjC::RewriteForwardClassDecl(DeclGroupRef D) {
std::string typedefString;
for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
- ObjCInterfaceDecl *ForwardDecl = cast<ObjCInterfaceDecl>(*I);
- if (I == D.begin()) {
- // Translate to typedef's that forward reference structs with the same name
- // as the class. As a convenience, we include the original declaration
- // as a comment.
- typedefString += "// @class ";
- typedefString += ForwardDecl->getNameAsString();
- typedefString += ";";
+ if (ObjCInterfaceDecl *ForwardDecl = dyn_cast<ObjCInterfaceDecl>(*I)) {
+ if (I == D.begin()) {
+ // Translate to typedef's that forward reference structs with the same name
+ // as the class. As a convenience, we include the original declaration
+ // as a comment.
+ typedefString += "// @class ";
+ typedefString += ForwardDecl->getNameAsString();
+ typedefString += ";";
+ }
+ RewriteOneForwardClassDecl(ForwardDecl, typedefString);
}
- RewriteOneForwardClassDecl(ForwardDecl, typedefString);
+ else
+ HandleTopLevelSingleDecl(*I);
}
DeclGroupRef::iterator I = D.begin();
RewriteForwardClassEpilogue(cast<ObjCInterfaceDecl>(*I), typedefString);
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,
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
@interface I
@end
@implementation I
-@protocol P; // expected-error {{Objective-C declarations may only appear in global scope}}
-@class C; // expected-error {{Objective-C declarations may only appear in global scope}}
-- (C<P>*) MyMeth {} // expected-error {{expected a type}}
+@protocol P; // forward declarations of protocols in @implementations is allowed
+@class C; // forward declarations of classes in @implementations is allowed
+- (C<P>*) MyMeth {}
@end
@interface I2 {}
@implementation I3
- Meth {}
+ Cls {}
-@protocol P3; // expected-error {{Objective-C declarations may only appear in global scope}}
+@protocol P3;
@end
-// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-runtime=macosx-fragile-10.5 %s -o %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
extern "C" {
};
+// rdar://15027032
+@interface ISDPropertyChangeGroup
+@end
+
+@implementation ISDPropertyChangeGroup
+@class ISDClientState;
+- (id)lastModifiedGeneration : (ISDClientState *) obj
+{
+ return obj ;
+}
+@end