https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50584

--- Comment #11 from joseph at codesourcery dot com <joseph at codesourcery dot 
com> ---
On Fri, 3 Jul 2015, sergei.ivn+bugzilla at gmail dot com wrote:

> Some excerpts from the C11 standard:
> 
> /-----
> If the keyword static also appears within the [ and ] of the array type
> derivation, then for each call to the function, the value of the corresponding
> actual argument shall provide access to the first element of an array with at
> least as many elements as specified by the size expression.
> \-----

This is in a Semantics section, not Constraints.

> I'm not sure about warnings (the meaning of the word "shall" is unclear for
> me), but IMO according to the standard null-pointers should issue an *error*.

"shall" is defined in clause 4, paragraph 2: 'If a "shall" or "shall not" 
requirement that appears outside of a constraint or runtime-constraint is 
violated, the behavior is undefined.'

In this case, the "shall" relates to a property of an execution of a 
program, not a property of the program itself.  Thus, undefined behavior 
only occurs on such an execution.  In particular, a program with such a 
call inside if (0) - or in any code that the compiler cannot prove will 
always be executed for all executions of the program - must *not* produce 
an error at compile time.  To quote the response to DR#109, "A conforming 
implementation must not fail to translate a strictly conforming program 
simply because some possible execution of that program would result in 
undefined behavior.".

Some such cases of runtime-undefined behavior get compiled into aborts, 
but this is only valid if the abort only occurs when the undefined 
function call would definitely be executed - not, for example, before the 
evaluation of another argument to the function that might exit the program 
or call longjmp (see previous bug fixes in this regard).

Reply via email to