This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

objc/7993: private variables cannot be shadowed in subclasses


>Number:         7993
>Category:       objc
>Synopsis:       private variables cannot be shadowed in subclasses
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 20 17:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Lorenz Minder
>Release:        3.3 20020916 (experimental)
>Organization:
>Environment:
System: Linux fanzthesecond 2.4.18 #33 Thu Jul 18 04:56:44 CEST 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-20020916/configure --enable-languages=objc
>Description:

If an instance variable is declared @private, the same variable name
can't be reused as name for local variables when implementing methods 
of subclasses.

This is wrong, because when writing subclasses you should not have to worry
about private implementation details of the superclass, such as names of
private variables. (I don't know, however, any official specification of
the Objective-C language, and therefore can't refer to any document
confirming my claim about the purpose of @private.)

The problem occurs in any of the gcc 3.x-versions I tested.

>How-To-Repeat:

The following code reproduces the problem:

@interface Base {
	@private
	int f;
}
@end

@interface Sub : Base {
}
-(float)squareOf:(float)f;
@end

@implementation Sub

-(float)squareOf:(float)g
{
	float f = g;
	return f*f;
}
@end

Compiling this I get the following error messages:

test1.m: In function `-[Sub squareOf:]':
test1.m:17: error: instance variable `f' is declared private
test1.m:17: warning: local declaration of `f' hides instance variable
test1.m:17: error: instance variable `f' is declared private
test1.m:17: warning: local declaration of `f' hides instance variable

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]