Debian Codegraph @

gcc/testsuite/obj-c++.dg/local-decl-1.mm

raw
1 /* Test for ivar access inside of class methods. It should be allowed
2 (with a warning), but only if no other declarations with the same
3 name are seen. */
4 /* Author: Ziemowit Laski <[email protected]>. */
5
6 /* { dg-do compile } */
7
8 #include "../objc-obj-c++-shared/TestsuiteObject.h"
9
10 @interface Sprite: TestsuiteObject {
11 int sprite, spree;
12 }
13 + (void)setFoo:(int)foo;
14 + (void)setSprite:(int)sprite;
15 - (void)setFoo:(int)foo;
16 - (void)setSprite:(int)sprite;
17 @end
18
19 int spree = 23;
20
21 @implementation Sprite
22 + (void)setFoo:(int)foo {
23 sprite = foo; /* { dg-warning "instance variable .sprite. accessed in class method" } */
24 spree = foo;
25 }
26 + (void)setSprite:(int)sprite {
27 int spree;
28 sprite = 15;
29 spree = 17;
30 ((Sprite *)self)->sprite = 16; /* NB: This is how one _should_ access */
31 ((Sprite *)self)->spree = 18; /* ivars from within class methods! */
32 }
33 - (void)setFoo:(int)foo {
34 sprite = foo;
35 spree = foo;
36 }
37 - (void)setSprite:(int)sprite {
38 int spree;
39 sprite = 15; /* { dg-warning "local declaration of .sprite. hides instance variable" } */
40 self->sprite = 16;
41 spree = 17; /* { dg-warning "local declaration of .spree. hides instance variable" } */
42 self->spree = 18;
43 }
44 @end