From: John McCall Date: Fri, 6 Aug 2010 00:46:05 +0000 (+0000) Subject: Properly pop out of Objective-C method declarations when they are (ill-formedly) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9983d2d76c8107672b5907124266f482ba03823f;p=clang Properly pop out of Objective-C method declarations when they are (ill-formedly) found within contexts other than the translation unit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110417 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a1580f14dc..96839a5421 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -343,8 +343,10 @@ DeclContext *Sema::getContainingDC(DeclContext *DC) { return DC; } + // ObjCMethodDecls are parsed (for some reason) outside the context + // of the class. if (isa(DC)) - return Context.getTranslationUnitDecl(); + return DC->getLexicalParent()->getLexicalParent(); return DC->getLexicalParent(); } diff --git a/test/SemaObjCXX/objc-decls-inside-namespace.mm b/test/SemaObjCXX/objc-decls-inside-namespace.mm index 9953ec366e..f68078b677 100644 --- a/test/SemaObjCXX/objc-decls-inside-namespace.mm +++ b/test/SemaObjCXX/objc-decls-inside-namespace.mm @@ -23,5 +23,10 @@ namespace C { @implementation A(C) //expected-error{{Objective-C declarations may only appear in global scope}} @end +@interface B @end //expected-error{{Objective-C declarations may only appear in global scope}} +@implementation B //expected-error{{Objective-C declarations may only appear in global scope}} ++ (void) foo {} +@end + }