Hi Joseph,

> Date: 2026-01-19 22:58:09+0000
> From: Joseph Myers <[email protected]>
>
> I don't believe my concerns about the interaction with parameter forward 
> declarations have been addressed in any revision of this patch.
> 
> This is genuinely an issue with the interaction of two features; it 
> doesn't arise with either feature in isolation.
> 
> (a) It's not an issue with parameter forward declarations in isolation 
> because the length of an array parameter *is not part of the type relevant 
> for any subsequent reference to or declaration of that parameter*, so 
> differences in array lengths cannot affect type compatibility or anything 
> else.
> 
> (b) It's not an issue with _Countof as it exists in C2Y because that only 
> applies to arrays, not to pointers, so the standard feature does not 
> provide a way to observe array lengths that do not end up forming part of 
> the type.
> 
> So when you introduce this interaction by adding _Countof on array 
> parameters, you need to (a) work out the desired semantics, (b) document 
> them, (c) implement them and (d) ensure they are properly covered in the 
> testsuite.  (Even defining as "not permitted on any parameter with a 
> forward declaration" to avoid these issues could be awkward when you might 
> not know at the point _Countof is encountered whether a previous parameter 
> referenced will turn out to be a forward declaration or not.)

I've been thinking about this, now that it's more or less certain that
forward parameter declarations won't be standardized.

I still refuse to define the behavior.  I think it's something a
programmer simply shouldn't use at all, and thus a contract for it is
bad.  However, I agree it's unnecessarily hostile to make it UB.

How about leaving it unspecified which of the multiple declarations are
used?  It's a generic-enough statement that programmers shouldn't rely
on any specific behavior, but it's generous enough that programmers will
know if one is 10 and the other is 20, we can't magically say 42.  And
the implementation is trivial.  And being unspecified, it would be the
door for an eventual diagnostic (I'm unable to implement that).  But we
can live without the diagnostic, IMO, because this isn't going to happen
in real code.

Does this sound reasonable to you?


Have a lovely night!
Alex

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

Attachment: signature.asc
Description: PGP signature

Reply via email to