Fix sizeof(char[a])

The sizes of VLAs need to be evaluated even inside sizeof,
i.e. when nocode_wanted is set.
This commit is contained in:
Michael Matz
2016-09-03 23:55:54 +02:00
parent 49bb5a7e06
commit 9656560f14
2 changed files with 25 additions and 12 deletions

View File

@ -2456,6 +2456,16 @@ void sizeof_test(void)
printf("__alignof__(short) = %d\n", __alignof__(short));
printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
printf("__alignof__(char) = %d\n", __alignof__(char));
printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
printf("__alignof__(func) = %d\n", __alignof__ sizeof_test());
/* sizes of VLAs need to be evaluated even inside sizeof: */
a = 2;
printf("sizeof(char[1+2*a]) = %d\n", sizeof(char[1+2*a]));
/* And checking if sizeof compound literal works. Parenthesized: */
printf("sizeof( (struct {int i; int j;}){4,5} ) = %d\n",
sizeof( (struct {int i; int j;}){4,5} ));
/* And as direct sizeof argument (as unary expression): */
printf("sizeof (struct {short i; short j;}){4,5} = %d\n",
sizeof (struct {short i; short j;}){4,5} );
}