[RFC] [PATCH] Add __array_size keyword

Stuart Brady sdb-gcc@zubnet.me.uk
Tue Feb 16 23:29:00 GMT 2016


On Tue, Feb 16, 2016 at 11:10:08PM +0000, Joseph Myers wrote:
> It sets it to be null - but does it diagnose conversion from integer to 
> pointer without a cast (it should do so if __array_size is not evaluating 
> to an integer constant expression, but not if it is evaluating to an 
> integer constant expression - hence this being one way to test whether 
> the result is an integer constant expression)?

With -Wall -Wextra, I do not see any such warning.  IIUC, the warning
would be given by -Wint-conversion, included in -Wall.  FWIW, if I use
"int a=1; void *p=a-a;" I do get the expected warning, so I think that
covers this case.  Is this right?

If I use __array_size in an enumeration, this works fine, rather than
giving me "error: enumerator value for ‘foo’ is not an integer constant".
I am not sure if this is not also a valid test.
-- 
Many thanks,
Stuart Brady



More information about the Gcc-patches mailing list