https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81141
Eric Gallager <egallager at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |egallager at gcc dot gnu.org --- Comment #6 from Eric Gallager <egallager at gcc dot gnu.org> --- (In reply to Martin Sebor from comment #0) > GCC detects the common mistake of using the (sizeof P / sizeof *P) > expression to attempt to compute the length of an array when P is a pointer. > A similar mistake is using the same expression when P is a zero-length > array because the result is zero, or a one-element array as the last element > of a struct because such an array is often used as a substitute for a > flexible array member. This is a enhancement request to add such a warning > (either under -Wsizeof-pointer-div or under a new option). What about -Wsizeof-array-div or -Wzero-length-bounds? (In reply to Martin Sebor from comment #0) > If this enhancement should be made available under a new warning option, > since the programming error it detects boils down to essentially the same > problem with the same conseequence, I would suggest to have the new option > subsume the -Wsizeof-pointer-div functionality as well. A possible name for > the new option might be -Wsizeof-division: "warn about uses of sizeof that > appear as if they attempt to compute the size of an array but do not > actually do so, or that may yield the wrong number of elements." How about -Wsizeof-division as an umbrella flag that enables both -Wsizeof-pointer-div and -Wsizeof-array-div?