NagyDonat wrote:

> The warning message may be still misleading if the LHS or RHS "arrays" are 
> non-array variables.

I think that the warning message is OK: "Subtraction of two pointers that do 
not point into the same array is undefined behavior." -- this also covers the 
case when one or both of the pointers do not point to arrays. (It doesn't 
mention the corner case that it's also valid to subtract two identical pointers 
that point to a non-array value, but that's completely irrelevant in practice, 
so wouldn't be a helpful suggestion.)

> (or detect if `offsetof` can be used and include it in the message)?

I think that would be a waste of time, because it's very rare that a project 
manually reimplements `offsetof` -- I think it only appears in `vim` becasue 
it's a very old codebase. (Also developers who play with this kind of low-level 
trickery should be familiar with the standard and understand what's the 
problem.)


https://github.com/llvm/llvm-project/pull/96501
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to