[cfe-dev] "static" array type derivation

Tim Northover Tim.Northover at arm.com
Thu Apr 19 02:34:43 PDT 2012


On Thursday 19 Apr 2012 00:09:58 Russell Harmon wrote:
> In the C standard section 6.7.5 point 7, it is stated that I can specify a
> type qualifier of "static" within the [ and ] of a function argument, the
> array provided upon every invocation of that function will be at least the
> size specified. I take this to mean that I can provide a minimum size
> (implying non-null) for a function argument, but my test code here
> https://gist.github.com/2417153 seems to indicate that although accepted,
> there is no enforcement of this in clang. Is my interpretation of the C
> standard correct? 

I believe so. The code you posted violates a "shall" clause, so it's undefined 
behaviour. However it doesn't violate any constraints clauses and it's 
syntactically correct so the compiler isn't required by the standard to 
produce a diagnostic -- it's just permitted to optimise as if you obeyed the 
rules.

It is, of course, a quality of implementation issue and warning about this 
would be better.

> If so, is there plans to add some (limited) compile-time checking of this?

I'm afraid I don't know of anyone planning to implement that warning, but I 
expect the standard comment that a patch would be good applies.

Tim.





More information about the cfe-dev mailing list