diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-02-22 16:30:03 +0100 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2017-03-04 00:45:38 +0800 |
| commit | f6ae9c86e4e212530350c80c72ee4fd580ee909e (patch) | |
| tree | d5bd7941b73a20c8e1960364b72976de4de9fedc /validation | |
| parent | ecb47e33d67a535716b4894c25cfe46c7abf1e3b (diff) | |
| download | sparse-dev-f6ae9c86e4e212530350c80c72ee4fd580ee909e.tar.gz | |
add test case for warnings about overlapping initializers
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/field-override.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/validation/field-override.c b/validation/field-override.c new file mode 100644 index 00000000..d5d00dfa --- /dev/null +++ b/validation/field-override.c @@ -0,0 +1,88 @@ +static int ref[] = { + [1] = 3, + [2] = 3, + [3] = 3, + [2] = 2, /* check-should-warn */ + [1] = 1, /* check-should-warn */ +}; + +static int foo[] = { + [1 ... 3] = 3, +}; + +static int foz[4] = { + [0 ... 3] = 3, + [0] = 0, + [1] = 0, + [2 ... 3] = 1, + [2] = 3, /* check-should-warn */ + [3] = 3, /* check-should-warn */ +}; + +static int bar[] = { + [1 ... 3] = 3, + [1] = 1, /* check-should-warn */ + [2] = 2, /* check-should-warn */ + [2 ... 4] = 2, /* check-should-warn */ + [2 ... 3] = 2, /* check-should-warn */ + [4] = 4, /* check-should-warn */ + [0] = 0, + [5] = 5, +}; + +static int baz[3][3] = { + [0 ... 2][0 ... 2] = 0, + [0] = { 0, 0, 0, }, /* check-should-warn */ + [0][0] = 1, /* check-should-warn */ + [1] = { 0, 0, 0, }, /* check-should-warn */ + [1][0] = 1, /* check-should-warn */ + [1][1] = 1, /* check-should-warn */ + [1 ... 2][1 ... 2] = 2, +}; + + +struct s { + int i; + int a[2]; +}; + +static struct s s = { + .a[0] = 0, + .a[1] = 1, +}; + +static struct s a[2] = { + [0].i = 0, + [1].i = 1, + [0].a[0] = 2, + [0].a[1] = 3, +}; + +static struct s b[2] = { + [0 ... 1] = { 0, { 1, 2 }, }, + [0].i = 0, + [1].i = 1, + [0].a[0] = 2, + [0].a[1] = 3, +}; + +/* + * check-name: field-override + * check-command: sparse -Woverride-init $file + * check-known-to-fail + * + * check-error-start +field-override.c:2:10: warning: Initializer entry defined twice +field-override.c:6:10: also defined here +field-override.c:14:10: warning: Initializer entry defined twice +field-override.c:15:10: also defined here +field-override.c:23:10: warning: Initializer entry defined twice +field-override.c:24:10: also defined here +field-override.c:23:10: warning: Initializer entry defined twice +field-override.c:25:10: also defined here +field-override.c:34:10: warning: Initializer entry defined twice +field-override.c:35:10: also defined here +field-override.c:62:10: warning: Initializer entry defined twice +field-override.c:63:10: also defined here + * check-error-end + */ |
