https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86532

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Bernd Edlinger from comment #8)
> $ cat part.c
> 
> const char a[2][3] = { "121", "1" };
> 
> int main ()
> {
>   int n = __builtin_strlen (&a[0][0]);
>   n += __builtin_strlen (a[0]);
> 
>   if (n != 8)
>     __builtin_abort ();
> }
> 
> 
> I think I find no way to stop this example from being miscompiled.

I bet Martin would argue it's invalid ...

The standard specifies initializing char[3] with "121" is valid.  7.24.1/1
specifies "if an array is accessed beyond the end of an object, the behavior
is undefined" where it is not clear how "object" relates to "array".

The definition of "string" doesn't talk about abstract layout so to me
doesn't rule out char str[1][5] or str[5][1].  It rules out struct { char c;
char d; } because of allowed padding.

Reply via email to