On Tue, 16 Feb 2016, Stuart Brady wrote: > 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?
What's right is: * In cases where it should return an integer constant (you've said that's when the argument is not a VLA, as for sizeof), there should be no diagnostic. * In cases where it should not return an integer constant, there should be such a diagnostic (enabled by default). The case I raised in my original message was e.g. int a; int b[2][a]; - should __array_size (b) be an integer constant (size_t)2, or should it be non-constant (size_t)2 because the argument is a VLA (albeit a VLA whose top-level dimension is an integer constant expression)? > 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. It's a valid test, *but* in various contexts, such as in an enumeration, you need -pedantic to enable diagnostics for some cases of invalid integer constant expressions (but for the null pointer constant case, you don't). -- Joseph S. Myers jos...@codesourcery.com