summaryrefslogtreecommitdiff
path: root/gcc/objc/objc-act.c
diff options
context:
space:
mode:
authorwood <wood@138bc75d-0d04-0410-961f-82ee72b054a4>1993-05-01 10:48:31 +0000
committerwood <wood@138bc75d-0d04-0410-961f-82ee72b054a4>1993-05-01 10:48:31 +0000
commite5299e715869335b8810617b7d78b9cc461d99c5 (patch)
treeacd7a164e29bdbeee353718f6085a6347cc53882 /gcc/objc/objc-act.c
parentbaa1f4f59550a053525688793d4b42ccd762c8ed (diff)
downloadgcc-e5299e715869335b8810617b7d78b9cc461d99c5.tar.gz
(build_ivar_reference): Warn when a class method
refers to an instance variable. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@4294 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/objc/objc-act.c')
-rw-r--r--gcc/objc/objc-act.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 6a973b6278a..0968f1e3bbd 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -4739,7 +4739,20 @@ build_ivar_reference (id)
tree id;
{
if (TREE_CODE (method_context) == CLASS_METHOD_DECL)
- TREE_TYPE (self_decl) = instance_type; /* cast */
+ {
+ /* Historically, a class method that produced objects (factory
+ method) would assign `self' to the instance that it
+ allocated. This would effectively turn the class method into
+ an instance method. Following this assignment, the instance
+ variables could be accessed. That practice, while safe,
+ violates the simple rule that a class method should not refer
+ to an instance variable. It's better to catch the cases
+ where this is done unknowingly than to support the above
+ paradigm. */
+ warning ("instance variable `%s' accessed in class method",
+ IDENTIFIER_POINTER (id));
+ TREE_TYPE (self_decl) = instance_type; /* cast */
+ }
return build_component_ref (build_indirect_ref (self_decl, "->"), id);
}