[LLVMdev] Is this a bug in clang?
David Vandevoorde
daveed at vandevoorde.com
Wed Apr 20 11:53:48 PDT 2011
On Apr 20, 2011, at 2:37 PM, John Regehr wrote:
>> It's the evaluation of the expression "i++ + i++" that result in undefined
>> behavior. If you merely compile a program that contains the expression, the
>> expression is never evaluated. You need to execute the program to have the
>> expression be evaluated and behavior be undefined.
>
> I don't think this is correct. The standard does not make much of a
> distinction between compile time and run time, there is merely a "C
> implementation."
>
>> For example, also, if you do `sizeof(i++ + i++)`, this behavior is perfectly
>> fine, and not undefined behavior. Because the `i++` is not evaluated.
>
> Probably also wrong.
No, Johannes is right: "undefined behavior" requires evaluation. Whether than evaluation happens at "compile/translation time" or "run time" doesn't matter (as you note: the standard's distinction between the two is implicit at best), but if the offending expression is e.g. in a function that never gets called, that expression doesn't cause undefined behavior.
Daveed
More information about the llvm-dev
mailing list