Is this a bug in clang?

Technically, it could've sent the mail before you even thought about
writing it. Undefined is undefined, there are no requirements. From:
Dustin Laurence

Technically, it could've sent the mail before you even thought about
writing it.

As a some-time student of General Relativity, technically, no it couldn't. :slight_smile:

...Undefined is undefined, there are no requirements.

The question was about which noun "undefined" qualifies--is it the behavior of the compiler which is undefined, or merely the behavior of the compiler's output? I gather the answer may be the former, while I'd have guessed that it is merely the latter. I suppose one argument in favor of the answer being the former is that it is the more insane answer, and therefore a priori more likely to be the decision of the committee. :slight_smile:

Not that it is greatly important that I know the answer, I guess, or I'd actually look it up.

Dustin

Ahmed Charles wrote:

Technically, it could've sent the mail before you even thought about
writing it. Undefined is undefined, there are no requirements. From:
Dustin Laurence
Sent: Wednesday, April 20, 2011 6:50 AM
To: llvmdev@cs.uiuc.edu
Subject: Re: [LLVMdev] Is this a bug in clang?

The compiler is perfectly within its rights to send a rude email to your
department chair if you compile that code.

Wouldn't it technically be only within its rights to compile code that
sends the rude email when executed, but not send the email itself? Or
are the undefined results of compilation not confined to the contents of
the executable file?

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.

For example, also, if you do `sizeof(i++ + i++)`, this behavior is perfectly
fine, and not undefined behavior. Because the `i++` is not evaluated.

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.

John

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

No, Johannes is right: "undefined behavior" requires evaluation.

Undefined behavior does not require evaluation. For example, undefined behavior occurs when "A nonempty source file does not end in a new-line character which is not immediately preceded by a backslash character or ends in a partial preprocessing token or comment."

John

I was commenting on the specific examples under discussion.

However, in a broad sense, you could think of translation phase #1 as "evaluating" whether the end of a source file has been reached.

  Daveed