On Fri, Aug 09, 2024 at 02:19:26PM +0200, Alejandro Colomar via Gcc wrote:
> 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?

You can compile your sources with -Werror=sizeof-array-argument if you want
it to be an error, but there is nothing wrong about using sizeof on function
argument with array type if you know what you're doing, and sizeof should be
usable on anything that has a size, not on everything except this special
case, so please don't enforce it on others.

        Jakub

Reply via email to