[cfe-dev] "static" array type derivation
rjmccall at apple.com
Thu Apr 19 16:37:10 CDT 2012
On Apr 19, 2012, at 5:34 AM, Tim Northover wrote:
> 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
> 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.
Yep. It would need to be implemented in a very performance-neutral way,
because I'm not sure I've ever seen an actual 'static' annotation in real code.
More information about the cfe-dev