From fce79ebc6c16676b106ade71356b3adfc11493e7 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 23 Mar 2012 23:24:23 +0000 Subject: [PATCH] Make sure we don't accept an @interface inside another objc container just because there was an attribute in front of it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153355 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 10 ++++++---- test/SemaObjC/incomplete-implementation.m | 2 +- test/SemaObjC/invalid-code.m | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 268ab368ce..27500fcd69 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2903,13 +2903,15 @@ Decl *Sema::ActOnMethodDeclaration( } bool Sema::CheckObjCDeclScope(Decl *D) { - if (isa(CurContext->getRedeclContext())) - return false; // Following is also an error. But it is caused by a missing @end // and diagnostic is issued elsewhere. - if (isa(CurContext->getRedeclContext())) { + if (isa(CurContext->getRedeclContext())) + return false; + + // If we switched context to translation unit while we are still lexically in + // an objc container, it means the parser missed emitting an error. + if (isa(getCurLexicalContext()->getRedeclContext())) return false; - } Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope); D->setInvalidDecl(); diff --git a/test/SemaObjC/incomplete-implementation.m b/test/SemaObjC/incomplete-implementation.m index df34a43f74..b10f9f629e 100644 --- a/test/SemaObjC/incomplete-implementation.m +++ b/test/SemaObjC/incomplete-implementation.m @@ -31,7 +31,7 @@ @implementation Q __attribute__((visibility("default"))) -@interface QN +@interface QN // expected-error {{Objective-C declarations may only appear in global scope}} { } @end diff --git a/test/SemaObjC/invalid-code.m b/test/SemaObjC/invalid-code.m index 4ba34f0e47..e06c5b566d 100644 --- a/test/SemaObjC/invalid-code.m +++ b/test/SemaObjC/invalid-code.m @@ -48,3 +48,7 @@ void foo() { // expected-warning {{cannot find interface declaration for 'SomeI'}} -(void)meth {} @end + +@interface I3 +__attribute__((unavailable)) @interface I4 @end // expected-error {{Objective-C declarations may only appear in global scope}} +@end -- 2.40.0