| 1 |
/* Contributed by Nicola Pero <[email protected]>, November 2010. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-Wall" } */ |
| 4 |
|
| 5 |
/* Test warnings with the dot-syntax. */ |
| 6 |
|
| 7 |
#include <stdlib.h> |
| 8 |
#include <objc/objc.h> |
| 9 |
#include <objc/runtime.h> |
| 10 |
|
| 11 |
@interface MyRootClass |
| 12 |
{ |
| 13 |
Class isa; |
| 14 |
id a; |
| 15 |
id b; |
| 16 |
int p1; |
| 17 |
int p2; |
| 18 |
} |
| 19 |
+ (id) initialize; |
| 20 |
+ (id) alloc; |
| 21 |
- (id) init; |
| 22 |
|
| 23 |
@property int p1; |
| 24 |
@property int p2; |
| 25 |
@end |
| 26 |
|
| 27 |
@implementation MyRootClass |
| 28 |
+ (id) initialize { return self; } |
| 29 |
+ (id) alloc { return class_createInstance (self, 0); } |
| 30 |
- (id) init { return self; } |
| 31 |
@synthesize p1; |
| 32 |
@synthesize p2; |
| 33 |
@end |
| 34 |
|
| 35 |
int main (void) |
| 36 |
{ |
| 37 |
MyRootClass *object = [[MyRootClass alloc] init]; |
| 38 |
|
| 39 |
/* First, test that the artificial code generated by dot-syntax does |
| 40 |
not generate unexpected warnings. */ |
| 41 |
|
| 42 |
/* All of the following should generate no warnings. */ |
| 43 |
object.p1 = 0; |
| 44 |
object.p2 = 0; |
| 45 |
object.p1 = object.p2 = 0; |
| 46 |
if (object.p1 > 0) |
| 47 |
object.p2 = 0; |
| 48 |
|
| 49 |
object.p1++; |
| 50 |
++object.p1; |
| 51 |
object.p1--; |
| 52 |
--object.p1; |
| 53 |
|
| 54 |
while (object.p1) |
| 55 |
object.p1--; |
| 56 |
|
| 57 |
/* Now test some warnings. */ |
| 58 |
object.p1; /* { dg-warning "value computed is not used" } */ |
| 59 |
|
| 60 |
/* TODO: It would be good to get the following to warn. */ |
| 61 |
if (object.p1 = 0) /* dg-warning "suggest parentheses around assignment used as truth value" */ |
| 62 |
abort (); |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
|