diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-03-23 23:24:23 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-03-23 23:24:23 +0000 |
| commit | 822c433a2756ec581399a2da6aa36689dc479200 (patch) | |
| tree | a883379b1b8a5ca82fc4e2521e9825a5c4190886 | |
| parent | aaf9743f5614285029cf004fd098ca32cc3ba2de (diff) | |
| download | bcm5719-llvm-822c433a2756ec581399a2da6aa36689dc479200.tar.gz bcm5719-llvm-822c433a2756ec581399a2da6aa36689dc479200.zip | |
Make sure we don't accept an @interface inside another objc container
just because there was an attribute in front of it.
llvm-svn: 153355
| -rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 10 | ||||
| -rw-r--r-- | clang/test/SemaObjC/incomplete-implementation.m | 2 | ||||
| -rw-r--r-- | clang/test/SemaObjC/invalid-code.m | 4 |
3 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 268ab368cea..27500fcd696 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -2903,13 +2903,15 @@ Decl *Sema::ActOnMethodDeclaration( } bool Sema::CheckObjCDeclScope(Decl *D) { - if (isa<TranslationUnitDecl>(CurContext->getRedeclContext())) - return false; // Following is also an error. But it is caused by a missing @end // and diagnostic is issued elsewhere. - if (isa<ObjCContainerDecl>(CurContext->getRedeclContext())) { + if (isa<ObjCContainerDecl>(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<TranslationUnitDecl>(getCurLexicalContext()->getRedeclContext())) return false; - } Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope); D->setInvalidDecl(); diff --git a/clang/test/SemaObjC/incomplete-implementation.m b/clang/test/SemaObjC/incomplete-implementation.m index df34a43f74a..b10f9f629ec 100644 --- a/clang/test/SemaObjC/incomplete-implementation.m +++ b/clang/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/clang/test/SemaObjC/invalid-code.m b/clang/test/SemaObjC/invalid-code.m index 4ba34f0e47d..e06c5b566d3 100644 --- a/clang/test/SemaObjC/invalid-code.m +++ b/clang/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 |

