Hi Joseph, On Mon, Jan 19, 2026 at 11:06:45PM +0000, Joseph Myers wrote: > On Mon, 19 Jan 2026, Alejandro Colomar wrote: > > > > Furthermore, _Countof for array parameters *does* introduce new issues > > > because compatibility above can only refer to the types *after* > > > adjustment, but with _Countof the question of matching lengths *before* > > > adjustment comes into play > > > > IMO, GCC already requires type compatibility on array parameters taking > > into account their length, as an extension. This is implemented as part > > of -Warray-parameter=. > > A warning (even if given at all in the forward declaration case) doesn't > exactly say what the semantics are for _Countof on array parameters when > the lengths differ. It says the code is questionable - and indeed it is. > But code that produces a warning (with no error) still has semantics, so > it needs to be clear what the semantics are for _Countof on array > parameters in this case. (And I'd be dubious of defining cases where the > lengths are different expressions as constraint violations simply because > of the possibility that they differ at runtime, since it's hard to define > a precise rule for when two expressions should be considered "the same".)
I'd indeed make them constraint violations. When it's a run-time value, it would be UB, just like happens with pointers to array. The idea is to bring array parameters to parity with pointers to array. Cheers, Alex -- <https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
