Hi Martin, On Thu, Aug 08, 2024 at 09:31:37AM GMT, Martin Uecker wrote: > Am Donnerstag, dem 08.08.2024 um 02:36 +0200 schrieb Alejandro Colomar: > > Hi Martin, > > > > Can we promote -Wno-sizeof-array-argument to a hard error? I don't > > think there's any legitimate use sizeof() on such a parameter. > > I am a bit worried that it might prevent people from adding size information > to arguments, by transforming later use of sizeof on such a pointer argument > into a hard error.
I've been thinking about it, and I'm not convinced. If we don't have an error, at some point, sizeof(array_param) would change meaning without prior notice. If a program uses that new feature, it will silently compile in older compiler versions, producing bogus results. To prevent that, the configure scripts would need to test the compiler and reject compilers that have the old behavior. However, if we introduce a mandatory compiler error, programs won't need to be careful about the feature. If the compiler supports it, it will compile, and if it doesn't, it will fail. Since I don't see any legitimate uses of sizeof(aparam) as of today, I don't expect having any consequences on existing code. (But please point me wrong if there are any, maybe in generic macros.) What do you think? > > So I would not do this at this time, until we have fully evolved the > size checking and the benefits are clear. > > > > > It would be an incompatible extension to ISO C, which would make sure > > that there are no remaining uses of sizeof(array_param), which would > > itself allow in the future --if n2906 or something similar is accepted-- > > repurposing sizeof() to return the size in bytes of the array (instead > > of the size of a pointer) without worrying about breaking existing code. > > I agree with this goal, but this is a long term goal. > > > Martin Cheers, Alex -- <https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature