Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The undefined behavior can still affect code generation even though the program gets translated.

It's just that the generated code may not do exactly what you expect it to do because the presence of undefined behavior allowed the compiler to make assumptions which may surprise you.

edit: It seems that I am incorrect



DR 109 allows that a program may be strictly conforming even if some possible executions of the program invoke UB:

> 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.

This text specifically allows for the case that a program is strictly conforming even if there is a possible execution that invokes UB. If a program is strictly conforming, it must produce the correct behavior.

I would challenge you to show an example where GCC or Clang will break the correctness of a program on account of UB that is not reached during program execution.

Here is an example where GCC and Clang specifically respects the correctness of a program as long as it does not reach the UB: https://godbolt.org/z/befWah77W


It seems that you may be correct.

At the very least I am unable to construct a counter-example so I concede this point




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: