From: Fariborz Jahanian Date: Mon, 22 Mar 2010 19:04:14 +0000 (+0000) Subject: Fixes access rues for ivars declared in class X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01f1bfc3284d5817517d35217885ea9ecb252817;p=clang Fixes access rues for ivars declared in class implementations (radar 7547942). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99198 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 752be5df7a..f1b2d1133f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -268,8 +268,6 @@ def err_duplicate_ivar_declaration : Error< "instance variable is already declared">; def warn_on_superclass_use : Warning< "class implementation may not have super class">; -def err_non_private_ivar_declaration : Error< - "only private ivars may be declared in implementation">; def err_conflicting_ivar_bitwidth : Error< "instance variable %0 has conflicting bit-field width">; def err_conflicting_ivar_name : Error< diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 7b2b6e855b..7a8aed7a21 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1236,7 +1236,7 @@ Parser::DeclPtrTy Parser::ParseObjCAtImplementationDeclaration( if (Tok.is(tok::l_brace)) // we have ivars ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, - tok::objc_protected, atLoc); + tok::objc_private, atLoc); ObjCImpDecl = ImplClsType; PendingObjCImpDecl.push_back(ObjCImpDecl); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index b2f671760e..1feeffdfe5 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -667,8 +667,6 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, Diag(ClsIvar->getLocation(), diag::note_previous_definition); continue; } - if (ImplIvar->getAccessControl() != ObjCIvarDecl::Private) - Diag(ImplIvar->getLocation(), diag::err_non_private_ivar_declaration); // Instance ivar to Implementation's DeclContext. ImplIvar->setLexicalDeclContext(ImpDecl); IDecl->makeDeclVisibleInContext(ImplIvar, false); diff --git a/test/SemaObjC/ivar-in-implementations.m b/test/SemaObjC/ivar-in-implementations.m index 32d3c353d0..4060526b44 100644 --- a/test/SemaObjC/ivar-in-implementations.m +++ b/test/SemaObjC/ivar-in-implementations.m @@ -11,12 +11,29 @@ @implementation INTFSTANDALONE : Super // expected-warning {{class implementation may not have super class}} { -@private - id IVAR1; + id PRIV_IVAR; @protected - id IVAR2; // expected-error {{only private ivars may be declared in implementation}} + id PRTCTD; @private id IVAR3; int IVAR; // expected-error {{instance variable is already declared}} +@public + id IVAR4; } @end + +@interface Base @end + +@implementation Base { + int ivar1; +@public + int ivar2; +} +@end + +id fn1(INTFSTANDALONE *b) { return b->PRIV_IVAR; } // expected-error {{instance variable 'PRIV_IVAR' is private}} + +id fn2(INTFSTANDALONE *b) { return b->PRTCTD; } // expected-error {{instance variable 'PRTCTD' is protected}} + +id fn4(INTFSTANDALONE *b) { return b->IVAR4; } +