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 + }