From: Fariborz Jahanian Date: Tue, 25 Sep 2007 21:00:20 +0000 (+0000) Subject: Patch to make ObjcImplementationDecl derived from TypeDecl and supprt legacy X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0da1c1033832b572d23ff2fe7bb2ab959768727e;p=clang Patch to make ObjcImplementationDecl derived from TypeDecl and supprt legacy objective-c code with no @interface declaration. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42319 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 9a52874f79..5470eb456b 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1105,6 +1105,14 @@ Sema::DeclTy *Sema::ObjcStartClassImplementation(Scope *S, ObjcImplementationDecl* IMPDecl = new ObjcImplementationDecl(AtClassImplLoc, ClassName, SDecl); + if (!IDecl) { + // Legacy case of @implementation with no corresponding @interface. + // Build, chain & install the interface decl into the identifier. + IDecl = new ObjcInterfaceDecl(AtClassImplLoc, 0, ClassName); + IDecl->setNext(ClassName->getFETokenInfo()); + ClassName->setFETokenInfo(IDecl); + + } // Check that there is no duplicate implementation of this class. bool err = false; diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 425e8711ea..7cb370b41c 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -858,7 +858,7 @@ public: static bool classof(const ObjcCategoryDecl *D) { return true; } }; -class ObjcImplementationDecl : public ScopedDecl { +class ObjcImplementationDecl : public TypeDecl { /// Implementation Class's super class. ObjcInterfaceDecl *SuperClass; @@ -878,7 +878,7 @@ class ObjcImplementationDecl : public ScopedDecl { public: ObjcImplementationDecl(SourceLocation L, IdentifierInfo *Id, ObjcInterfaceDecl* superDecl) - : ScopedDecl(ObjcImplementation, L, Id, 0), + : TypeDecl(ObjcImplementation, L, Id, 0), SuperClass(superDecl), Ivars(0), NumIvars(-1), InsMethods(0), NumInsMethods(-1), ClsMethods(0), NumClsMethods(-1) {} diff --git a/test/Sema/objc-legacy-implementation-1.m b/test/Sema/objc-legacy-implementation-1.m new file mode 100644 index 0000000000..c706ec7543 --- /dev/null +++ b/test/Sema/objc-legacy-implementation-1.m @@ -0,0 +1,9 @@ +@implementation INTF // expected-warning {{cannot find interface declaration for 'INTF'}} +@end + +INTF* pi; + +INTF* FUNC() +{ + return pi; +}