diff options
author | John McCall <rjmccall@apple.com> | 2010-08-06 00:46:05 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-08-06 00:46:05 +0000 |
commit | 9983d2d76c8107672b5907124266f482ba03823f (patch) | |
tree | 190198b65dfa9ddd33f67830a5f7969f1498e3e2 | |
parent | f65339e0f1b9ccfc0c92c85f68bb2e72ea48a27b (diff) |
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
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 4 | ||||
-rw-r--r-- | test/SemaObjCXX/objc-decls-inside-namespace.mm | 5 |
2 files changed, 8 insertions, 1 deletions
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<ObjCMethodDecl>(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 + } |