annotate clang/test/SemaObjC/ivar-ref-misuse.m @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 @interface Sprite {
anatofuz
parents:
diff changeset
4 int sprite, spree;
anatofuz
parents:
diff changeset
5 int UseGlobalBar;
anatofuz
parents:
diff changeset
6 }
anatofuz
parents:
diff changeset
7 + (void)setFoo:(int)foo;
anatofuz
parents:
diff changeset
8 + (void)setSprite:(int)sprite;
anatofuz
parents:
diff changeset
9 - (void)setFoo:(int)foo;
anatofuz
parents:
diff changeset
10 - (void)setSprite:(int)sprite;
anatofuz
parents:
diff changeset
11 @end
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 int spree = 23;
anatofuz
parents:
diff changeset
14 int UseGlobalBar;
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 @implementation Sprite
anatofuz
parents:
diff changeset
17 + (void)setFoo:(int)foo {
anatofuz
parents:
diff changeset
18 sprite = foo; // expected-error {{instance variable 'sprite' accessed in class method}}
anatofuz
parents:
diff changeset
19 spree = foo;
anatofuz
parents:
diff changeset
20 Xsprite = foo; // expected-error {{use of undeclared identifier 'Xsprite'}}
anatofuz
parents:
diff changeset
21 UseGlobalBar = 10;
anatofuz
parents:
diff changeset
22 }
anatofuz
parents:
diff changeset
23 + (void)setSprite:(int)sprite {
anatofuz
parents:
diff changeset
24 int spree;
anatofuz
parents:
diff changeset
25 sprite = 15;
anatofuz
parents:
diff changeset
26 spree = 17;
anatofuz
parents:
diff changeset
27 ((Sprite *)self)->sprite = 16; /* NB: This is how one _should_ access */
anatofuz
parents:
diff changeset
28 ((Sprite *)self)->spree = 18; /* ivars from within class methods! */
anatofuz
parents:
diff changeset
29 }
anatofuz
parents:
diff changeset
30 - (void)setFoo:(int)foo {
anatofuz
parents:
diff changeset
31 sprite = foo;
anatofuz
parents:
diff changeset
32 spree = foo;
anatofuz
parents:
diff changeset
33 }
anatofuz
parents:
diff changeset
34 - (void)setSprite:(int)sprite {
anatofuz
parents:
diff changeset
35 int spree;
anatofuz
parents:
diff changeset
36 sprite = 15; // expected-warning {{local declaration of 'sprite' hides instance variable}}
anatofuz
parents:
diff changeset
37 self->sprite = 16;
anatofuz
parents:
diff changeset
38 spree = 17; // expected-warning {{local declaration of 'spree' hides instance variable}}
anatofuz
parents:
diff changeset
39 self->spree = 18;
anatofuz
parents:
diff changeset
40 }
anatofuz
parents:
diff changeset
41 @end