File: initializer-entry-defined-twice.c

package info (click to toggle)
sparse 0.4.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: lenny
  • size: 1,268 kB
  • ctags: 2,691
  • sloc: ansic: 23,892; perl: 204; sh: 181; makefile: 174
file content (53 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download | duplicates (2)
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
/* Tests for the "Initializer entry defined twice" warning. */

/* Initializing a struct field twice should trigger the warning. */
struct normal {
	int field1;
	int field2;
};

static struct normal struct_error = {
	.field1 = 0,
	.field1 = 0
};

/* Initializing two different fields of a union should trigger the warning. */
struct has_union {
	int x;
	union {
		int a;
		int b;
	} y;
	int z;
};

static struct has_union union_error = {
	.y = {
		.a = 0,
		.b = 0
	}
};

/* Empty structures can make two fields have the same offset in a struct.
 * Initializing both should not trigger the warning. */
struct empty { };

struct same_offset {
	struct empty field1;
	int field2;
};

static struct same_offset not_an_error = {
	.field1 = { },
	.field2 = 0
};
/*
 * check-name: Initializer entry defined twice
 *
 * check-error-start
initializer-entry-defined-twice.c:10:3: warning: Initializer entry defined twice
initializer-entry-defined-twice.c:11:3:   also defined here
initializer-entry-defined-twice.c:26:4: warning: Initializer entry defined twice
initializer-entry-defined-twice.c:27:4:   also defined here
 * check-error-end
 */