On Wed, 7 Oct 2026, Alejandro Colomar wrote:

> The strict rules would be that it's a constraint to have the forward
> declaration of a parameter contradict the declaration, and thus a
> constraint violation.  However, implementing those diagnostics would be
> non-trivial for me.

My suggestion would be to be strict on the new feature (e.g. disallow 
_Countof for any parameter for which both a forward declaration and 
another declaration of the parameter are visible) rather than adding extra 
checks for consistency of forward parameter declarations.

>         int
>         g(int n, int m, int a[][n]; int n, int m, int a[][m])
>         {
>                 return _Countof(a[0]);

The cases of concern to me are where the length of the parameter array 
itself might vary between the declarations (or one declaration might be a 
pointer and another an array), because those are the ones where the new 
extension of _Countof on array parameters actually comes into play and 
starts interacting with forward declarations.

This example is using _Countof on something that has array type in the 
existing language for all purposes - not on an array parameter that's 
adjusted to a pointer for most purposes.  So it already has undefined 
behavior at runtime if the two declarations (adjusted to pointer-to-array 
type) specify different lengths n and m, and that doesn't depend on the 
use of _Countof, only on the function being called with n != m.

-- 
Joseph S. Myers
[email protected]

Reply via email to