Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The C++ specification leaves a lot of leeway such that when you write bad code,

ID: 658904 • Letter: T

Question

The C++ specification leaves a lot of leeway such that when you write bad code, compiler authors are not responsible for defining a specific mode of failure. We know of course that is Undefined Behavior.

(For those unaware, once there was a cutesy stunt to launch Tetris if you used a #pragma in GCC, which is actually implementation-defined behavior, but it ties into the whole shebang.)

This made me wonder about what the full coverage list of "erroring" conditions are:

(1) That code will not compile.

(2) That code has undefined behavior.

(3) That code will throw an exception.

CAUTION: [JOKE]

(4) That code will not terminate.

I'm working on a compiler, and I'm almost finished with the part that checks #4 (the solution is too long to post in this forum). But in the meantime...

END CAUTION [/JOKE]

My question is: what can you and can't you say?

The motivation is from someone declaring that you cannot use the phrase "that code should crash". I said "will crash" and "should crash" are different; but that aside, I started wondering if the only thing the specifications have defined are 1, 2, 3.

Explanation / Answer

There are only two. The first is that the code will be rejected by the compiler. The other is that it has undefined behaviour. Throwing an exception is not an error and failing to terminate is undefined behaviour.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote