From patchwork Sun Oct 17 21:53:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 68096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 28772B70A7 for ; Mon, 18 Oct 2010 08:53:13 +1100 (EST) Received: (qmail 31751 invoked by alias); 17 Oct 2010 21:53:11 -0000 Received: (qmail 31743 invoked by uid 22791); 17 Oct 2010 21:53:10 -0000 X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL, BAYES_20, TW_BJ, TW_ZJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 17 Oct 2010 21:53:05 +0000 Received: from eggs.gnu.org ([140.186.70.92]:39951) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P7bA7-0008Tr-3p for gcc-patches@gnu.org; Sun, 17 Oct 2010 17:53:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7bA5-0001hn-L4 for gcc-patches@gnu.org; Sun, 17 Oct 2010 17:53:03 -0400 Received: from smtp201.iad.emailsrvr.com ([207.97.245.201]:60739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7bA5-0001hj-HS for gcc-patches@gnu.org; Sun, 17 Oct 2010 17:53:01 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp50.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id C8D84370205 for ; Sun, 17 Oct 2010 17:53:00 -0400 (EDT) X-Orig-To: gcc-patches@gnu.org Received: from dynamic7.wm-web.iad.mlsrvr.com (dynamic7.wm-web.iad1a.rsapps.net [192.168.2.148]) by smtp50.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id A8C8D3701F8 for ; Sun, 17 Oct 2010 17:53:00 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic7.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 7D1D2153806A for ; Sun, 17 Oct 2010 17:53:00 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sun, 17 Oct 2010 23:53:00 +0200 (CEST) Date: Sun, 17 Oct 2010 23:53:00 +0200 (CEST) Subject: ObjC/ObjC++ - another small merge from apple/trunk From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1287352380.510922717@192.168.2.228> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This improves the error message when accessing ObjC/ObjC++ private instance variables. Committed to trunk (preapproved by Mike) Thanks In gcc/: 2010-10-17 Nicola Pero Merge from 'apple/trunk' branch on FSF servers. 2006-03-27 Fariborz Jahanian Radar 4133425 * c-decl.c (undeclared_variable): Issue diagnostic on private 'ivar' access. In gcc/c-family/: 2010-10-17 Nicola Pero Merge from 'apple/trunk' branch on FSF servers. 2006-03-27 Fariborz Jahanian Radar 4133425 * c-common.h (objc_diagnose_private_ivar): New decl. * stub-objc.c (objc_diagnose_private_ivar): New stub. In gcc/cp/: 2010-10-17 Nicola Pero Merge from apple/trunk branch on FSF servers. 2006-03-27 Fariborz Jahanian Radar 4133425 * lex.c (unqualified_name_lookup_error): Issue diagnostic for private 'ivar' access. In gcc/objc/: 2010-10-17 Nicola Pero Merge from 'apple/trunk' branch on FSF servers. 2006-03-27 Fariborz Jahanian Radar 4133425 * objc-act.c (objc_diagnose_private_ivar): New. In gcc/testsuite/: 2010-10-17 Nicola Pero Merge from 'apple/trunk' branch on FSF servers. 2006-03-27 Fariborz Jahanian Radar 4133425 * objc.dg/private-1.m: Test modified. * obj-c++.dg/private-1.mm: Test modified. Index: gcc/c-family/ChangeLog =================================================================== --- gcc/c-family/ChangeLog (revision 165600) +++ gcc/c-family/ChangeLog (working copy) @@ -1,3 +1,13 @@ +2010-10-17 Nicola Pero + + Merge from 'apple/trunk' branch on FSF servers. + + 2006-03-27 Fariborz Jahanian + + Radar 4133425 + * c-common.h (objc_diagnose_private_ivar): New decl. + * stub-objc.c (objc_diagnose_private_ivar): New stub. + 2010-10-17 Iain Sandoe * c-common.c (c_common_reswords): Add package, RID_AT_PACKAGE. Index: gcc/c-family/c-common.h =================================================================== --- gcc/c-family/c-common.h (revision 165600) +++ gcc/c-family/c-common.h (working copy) @@ -987,6 +987,7 @@ extern void objc_check_global_decl (tree); extern tree objc_common_type (tree, tree); extern bool objc_compare_types (tree, tree, int, tree); extern bool objc_have_common_type (tree, tree, int, tree); +extern bool objc_diagnose_private_ivar (tree); extern void objc_volatilize_decl (tree); extern bool objc_type_quals_match (tree, tree); extern tree objc_rewrite_function_call (tree, tree); Index: gcc/c-family/stub-objc.c =================================================================== --- gcc/c-family/stub-objc.c (revision 165600) +++ gcc/c-family/stub-objc.c (working copy) @@ -44,6 +44,11 @@ objc_is_object_ptr (tree ARG_UNUSED (arg)) return 0; } +bool objc_diagnose_private_ivar (tree ARG_UNUSED (arg)) +{ + return false; +} + tree objc_lookup_ivar (tree other, tree ARG_UNUSED (arg)) { Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c (revision 165600) +++ gcc/objc/objc-act.c (working copy) @@ -10821,6 +10821,25 @@ generate_objc_image_info (void) finish_var_decl (decl, objc_build_constructor (TREE_TYPE (decl), v)); } +/* Routine is called to issue diagnostic when reference to a private + ivar is made and no other variable with same name is found in + current scope. */ +bool +objc_diagnose_private_ivar (tree id) +{ + tree ivar; + if (!objc_method_context) + return false; + ivar = is_ivar (objc_ivar_chain, id); + if (ivar && is_private (ivar)) + { + error ("instance variable %qs is declared private", + IDENTIFIER_POINTER (id)); + return true; + } + return false; +} + /* Look up ID as an instance variable. OTHER contains the result of the C or C++ lookup, which we may want to use instead. */ /* Also handle use of property as setter/getter. */ Index: gcc/objc/ChangeLog =================================================================== --- gcc/objc/ChangeLog (revision 165600) +++ gcc/objc/ChangeLog (working copy) @@ -1,3 +1,12 @@ +2010-10-17 Nicola Pero + + Merge from 'apple/trunk' branch on FSF servers. + + 2006-03-27 Fariborz Jahanian + + Radar 4133425 + * objc-act.c (objc_diagnose_private_ivar): New. + 2010-10-17 Iain Sandoe * objc-act.c: Rename 'objc_public_flag' to objc_ivar_visibility and Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 165600) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,13 @@ +2010-10-17 Nicola Pero + + Merge from 'apple/trunk' branch on FSF servers. + + 2006-03-27 Fariborz Jahanian + + Radar 4133425 + * c-decl.c (undeclared_variable): Issue diagnostic on + private 'ivar' access. + 2010-10-17 Uros Bizjak PR target/46051 Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 165600) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,13 @@ +2010-10-17 Nicola Pero + + Merge from 'apple/trunk' branch on FSF servers. + + 2006-03-27 Fariborz Jahanian + + Radar 4133425 + * objc.dg/private-1.m: Test modified. + * obj-c++.dg/private-1.mm: Test modified. + 2010-10-17 Uros Bizjak PR testsuite/45987 Index: gcc/testsuite/objc.dg/private-1.m =================================================================== --- gcc/testsuite/objc.dg/private-1.m (revision 165600) +++ gcc/testsuite/objc.dg/private-1.m (working copy) @@ -34,7 +34,7 @@ - (void) test { /* Private variables simply don't exist in the subclass. */ - private = 12;/* { dg-error "undeclared" } */ + private = 12; /* { dg-error "instance variable" } */ /* { dg-message "function it appears in" "" { target *-*-* } { 37 } } */ protected = 12; /* Ok */ Index: gcc/testsuite/obj-c++.dg/private-1.mm =================================================================== --- gcc/testsuite/obj-c++.dg/private-1.mm (revision 165600) +++ gcc/testsuite/obj-c++.dg/private-1.mm (working copy) @@ -1,8 +1,6 @@ /* Test errors for accessing @private and @protected variables. */ /* Based on work by: Nicola Pero . */ - /* { dg-do compile } */ - #include @interface MySuperClass @@ -36,7 +34,7 @@ - (void) test { /* Private variables simply don't exist in the subclass. */ - _private = 12; /* { dg-error "._private. was not declared in this scope" } */ + _private = 12; /* { dg-error "instance variable \\'_private\\' is declared private" } */ _protected = 12; /* Ok */ _public = 12; /* Ok */ Index: gcc/cp/ChangeLog =================================================================== --- gcc/cp/ChangeLog (revision 165600) +++ gcc/cp/ChangeLog (working copy) @@ -1,3 +1,13 @@ +2010-10-17 Nicola Pero + + Merge from apple/trunk branch on FSF servers. + + 2006-03-27 Fariborz Jahanian + + Radar 4133425 + * lex.c (unqualified_name_lookup_error): Issue diagnostic + for private 'ivar' access. + 2010-10-17 Iain Sandoe * parser.c (cp_parser_objc_visibility_spec): Update to use visibility Index: gcc/cp/lex.c =================================================================== --- gcc/cp/lex.c (revision 165600) +++ gcc/cp/lex.c (working copy) @@ -449,7 +449,8 @@ unqualified_name_lookup_error (tree name) } else { - error ("%qD was not declared in this scope", name); + if (!objc_diagnose_private_ivar (name)) + error ("%qD was not declared in this scope", name); /* Prevent repeated error messages by creating a VAR_DECL with this NAME in the innermost block scope. */ if (current_function_decl) Index: gcc/c-decl.c =================================================================== --- gcc/c-decl.c (revision 165600) +++ gcc/c-decl.c (working copy) @@ -2961,7 +2961,8 @@ undeclared_variable (location_t loc, tree id) } else { - error_at (loc, "%qE undeclared (first use in this function)", id); + if (!objc_diagnose_private_ivar (id)) + error_at (loc, "%qE undeclared (first use in this function)", id); if (!already) { inform (loc, "each undeclared identifier is reported only"