tests/lint: ensure initialization does not modify shared type
In my not yet published rewrite of lint's init.c, I forgot to copy the array type. Guard against this bug, which would have been hard to find. Given that in C, the declaration 'int a[], b[]' creates two different type objects anyway, it's not easy to come up with a test case that actually triggers this possible bug. I'm not sure whether this test indeed catches this bug. If not, I'll add another test.
This commit is contained in:
parent
bcdf6c3e99
commit
4bf66febf4
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: d_c99_init.c,v 1.20 2021/03/29 17:13:07 rillig Exp $ */
|
||||
/* $NetBSD: d_c99_init.c,v 1.21 2021/03/29 22:07:00 rillig Exp $ */
|
||||
# 3 "d_c99_init.c"
|
||||
|
||||
/*
|
||||
|
@ -306,3 +306,25 @@ short c99_6_7_8_p29_example6c[4][3][2] = {
|
|||
{ 6 },
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* During initialization of an object of type array of unknown size, the type
|
||||
* information on the symbol is updated in-place. Ensure that this happens on
|
||||
* a copy of the type.
|
||||
*/
|
||||
void
|
||||
ensure_array_type_is_not_modified_during_initialization(void)
|
||||
{
|
||||
typedef int array_of_unknown_size[];
|
||||
|
||||
array_of_unknown_size a1 = { 1, 2, 3};
|
||||
|
||||
switch (4) {
|
||||
case sizeof(array_of_unknown_size):
|
||||
case 0: /* expect: duplicate case in switch: 0 */
|
||||
case 3:
|
||||
case 4:
|
||||
case 12:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,3 +5,4 @@ d_c99_init.c(145): error: syntax error 'named member must only be used with stru
|
|||
d_c99_init.c(232): error: too many struct/union initializers [172]
|
||||
d_c99_init.c(238): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
|
||||
d_c99_init.c(244): error: too many array initializers, expected 8 [173]
|
||||
d_c99_init.c(324): error: duplicate case in switch: 0 [199]
|
||||
|
|
Loading…
Reference in New Issue