Hi Joseph,

On Fri, Jan 16, 2026 at 02:44:15PM +0100, Alejandro Colomar wrote:
> Hi Joseph,
> 
> On Fri, Jan 16, 2026 at 01:06:41AM +0100, Alejandro Colomar wrote:
> > Hi Joseph,
> > 
> > On Thu, Jan 15, 2026 at 11:33:10PM +0000, Joseph Myers wrote:
> > > On Thu, 15 Jan 2026, Alejandro Colomar wrote:
> > > 
> > > > I recently discovered that we wouldn't be introducing and new undefined
> > > > behavior.  That same undefined behavior already exists today in GCC 16:
> > > 
> > > You can't deduce UB from how the compiler behaves on this particular 
> > > input.  You need to specify the semantics so that then we can see if 
> > > there 
> > > is UB either explicitly or implicitly.

I've sent a patch for improving the documentation.  However, the current
documentation already specifies this as UB:

<https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html>
        Each parameter forward declaration must match a parameter
        declaration in parameter name and data type.

int[][n] and int[][n+1] do not "match", and thus the behavior is
undefined.


Have a lovely night!
Alex

> > Hmmmm, then we should document the behavior of _Countof() in GCC 16 for
> 
> Actually, not even a GCC 16 or _Countof() thing.  This happened with
> sizeof() before too.
> 
>       alx@devuan:~/tmp$ cat cap.c 
>       int
>       f(int n, char a[][n]; int n, char a[][n+1])
>       {
>               return sizeof(a[0]);
>       }
> 
>       int
>       main(void)
>       {
>               char a[42];
> 
>               return f(42, &a);
>       }
>       alx@devuan:~/tmp$ gcc -Wall -Wextra cap.c 
>       alx@devuan:~/tmp$ ./a.out 
>       alx@devuan:~/tmp$ echo $?
>       43
> 
> > pointers to arrays when interacting with forward declarations of
> > parameters, right?  
> > 
> > Then, array parameters would just be consistent with that.
> > 
> > That makes sense to me.
> > 
> > Should I document it as part of _Countof() or as part of forward
> > declarations of parameters?  Do you have any preference?
> 
> It should be documented as part of forward declarations of parameters,
> as this is not inherent to _Countof().
> 
> 
> Have a lovely day!
> Alex
> 
> -- 
> <https://www.alejandro-colomar.es>



-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to