summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/sync-3.m
blob: 5cee890bba2e7db943b62cabd9412583cc0c5ecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, December 2010.  */
/* { dg-options "-fobjc-exceptions" } */
/* { dg-do compile } */

/* Test that the compiler is checking the argument of @synchronized(),
   and produce errors when invalid types are used.  */

#include <objc/objc.h>

@interface MyObject
{
  Class isa;
}
@end

@implementation MyObject
@end

@protocol MyProtocol;

typedef MyObject MyObjectTypedef;
typedef MyObject *MyObjectPtrTypedef;
typedef int intTypedef;

typedef struct { float x; float y; } point, *point_ptr;

int test (id object)
{
  int dummy = 0;

  {
    int x;
    @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
    { dummy++; }
  }

  {
    intTypedef x;
    @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
    { dummy++; }
  }

  {
    int *x;
    @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
    { dummy++; }
  }

  {
    point x;
    @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
    { dummy++; }
  }

  {
    point_ptr x;
    @synchronized (x) /* { dg-error ".@synchronized. argument is not an object" } */
    { dummy++; }
  }

  {
    id x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    id <MyProtocol> x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    MyObject *x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    MyObject <MyProtocol> *x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    static MyObject *x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    MyObjectTypedef *x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    MyObjectTypedef <MyProtocol> *x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    MyObjectPtrTypedef x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  {
    Class x;
    @synchronized (x) /* Ok */
    { dummy++; }
  }

  @synchronized (1) /* { dg-error ".@synchronized. argument is not an object" } */
    { dummy++; }

  @synchronized ("Test") /* { dg-error ".@synchronized. argument is not an object" } */
    { dummy++; }

  @synchronized () /* { dg-error "expected expression" } */
    { dummy++; }

  @synchronized (int) /* { dg-error "expected expression" } */
    { dummy++; }

  return dummy;
}