[cfe-commits] r153355 - in /cfe/trunk: lib/Sema/SemaDeclObjC.cpp test/SemaObjC/incomplete-implementation.m test/SemaObjC/invalid-code.m
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Mar 23 16:24:23 PDT 2012
Author: akirtzidis
Date: Fri Mar 23 18:24:23 2012
New Revision: 153355
URL: http://llvm.org/viewvc/llvm-project?rev=153355&view=rev
Log:
Make sure we don't accept an @interface inside another objc container
just because there was an attribute in front of it.
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/incomplete-implementation.m
cfe/trunk/test/SemaObjC/invalid-code.m
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=153355&r1=153354&r2=153355&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Mar 23 18:24:23 2012
@@ -2903,13 +2903,15 @@
}
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();
Modified: cfe/trunk/test/SemaObjC/incomplete-implementation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/incomplete-implementation.m?rev=153355&r1=153354&r2=153355&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/incomplete-implementation.m (original)
+++ cfe/trunk/test/SemaObjC/incomplete-implementation.m Fri Mar 23 18:24:23 2012
@@ -31,7 +31,7 @@
@implementation Q
__attribute__((visibility("default")))
- at interface QN
+ at interface QN // expected-error {{Objective-C declarations may only appear in global scope}}
{
}
@end
Modified: cfe/trunk/test/SemaObjC/invalid-code.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/invalid-code.m?rev=153355&r1=153354&r2=153355&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/invalid-code.m (original)
+++ cfe/trunk/test/SemaObjC/invalid-code.m Fri Mar 23 18:24:23 2012
@@ -48,3 +48,7 @@
// expected-warning {{cannot find interface declaration for 'SomeI'}}
-(void)meth {}
@end
+
+ at interface I3
+__attribute__((unavailable)) @interface I4 @end // expected-error {{Objective-C declarations may only appear in global scope}}
+ at end
More information about the cfe-commits
mailing list