aboutsummaryrefslogtreecommitdiff
path: root/test/attribute-syntax.c
blob: 1be426064d150ec7a0e7561dcd439e89dc249953 (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
/* applies to a and b */
[[dummy]] int a, b;

/* applies only to d */
int c, d [[dummy]];

/* applies to type int in this instance */
int [[dummy]] x;

/* applies to array type */
int array[8] [[dummy]];

/* applies to function type */
int function(void) [[dummy]];

/* applies to pointer type */
int *[[dummy]]const pointer;

/* standalone attribute is implementation-defined */
[[dummy]];

/* applies to type `struct s`, here and elsewhere */
struct [[dummy]] s {
	/* applies to i */
	[[dummy]] int i;

	/* applies to type float in this instance */
	float [[dummy]] f;
};

/* applies to type `union u`, here and elsewhere */
union [[dummy]] u {
	/* applies to i */
	[[dummy]] int i;

	/* applies to type float in this instance */
	float [[dummy]] f;
};

/* applies to type `enum e`, here and elsewhere */
enum [[dummy]] e {
	/* applies to E1 */
	E1 [[dummy]],

	/* applies to E2 */
	E2 [[dummy]] = 123,
};

/* applies to function */
[[dummy]] void f([[dummy]] int p1 /* applies to p1 */, int [[dummy]] p2 /* applies to type int */) {
	/* applies to type int */
	sizeof(int [[dummy]]);

	/* applies to array type */
	sizeof(int[4] [[dummy]]);

	/* applies to function type */
	sizeof(int (*)(float) [[dummy]]);

	/* applies to pointer type */
	sizeof(int *[[dummy]]);

	/* applies to statement */
	[[dummy]]
	if (0)
		;

	/* applies to label */
	[[dummy]]
	L1: 0;

	/* applies to statement */
	L2: [[dummy]]0;
}

[[dummy(attribute with parameters [123 456 ({+ -} if else)])]];
[[dummy1,dummy2,,dummy3]];
[[]];
[[dummy1]] [[dummy2]];