------- Comment #6 from burnus at gcc dot gnu dot org 2010-07-08 20:28 ------- (In reply to comment #5) > compilation output > X=3, 4.5 ok, but no truncation warning "123678"
The warning should be only printed with -Wcharacter-truncation (i.e. not by default), but I agree a warning would be nice. > X=7, 4.5 ok "1234567890" <-- wrong? As one sees from the output - the last characters are still uninitialized (i.e. '\0' as it is static variable): 0000000 3120 3332 3534 0000 3736 3938 0030 0a00 sp 1 2 3 4 5 nul nul 6 7 8 9 0 nul nul nl The issue is that the initializer is not space padded, i.e. (od -h -a) static struct t tt = {.txt={"12345", "67890"}}; should be static struct t tt = {.txt={"12345 ", "67890 "}}; For non-static initialization this works (GCC 4.5 and 4.6). > X=3, trunk ok, but no truncation warning "1236" <-- wrong Here, the dump looks as: static struct t tt = {.txt={"12345", "67890"}}; Thus, in case of 4.5 we forget to pad while for 4.6 we forget to pad and to truncate. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44857