]> granicus.if.org Git - clang/commitdiff
Properly pop out of Objective-C method declarations when they are (ill-formedly)
authorJohn McCall <rjmccall@apple.com>
Fri, 6 Aug 2010 00:46:05 +0000 (00:46 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 6 Aug 2010 00:46:05 +0000 (00:46 +0000)
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

lib/Sema/SemaDecl.cpp
test/SemaObjCXX/objc-decls-inside-namespace.mm

index a1580f14dc521e0c3e71382502bf4d25136d2ac3..96839a542133855eb726dfe3e8334668964d25bf 100644 (file)
@@ -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();
 }
index 9953ec366e1625beca1b6dec467f0cbd0187b2c5..f68078b6779d5232e774f25ae7af5633495ca2fe 100644 (file)
@@ -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
+
 }