Holy crap, clang in C++ mode is *evil*!
https://godbolt.org/z/hM7W1WPsE
gcc at least puts a `ud2` in there...
Holy crap, clang in C++ mode is *evil*!
https://godbolt.org/z/hM7W1WPsE
gcc at least puts a `ud2` in there...
@lina in c++26 mode too?
@lina eh. Is it really evil? The code invokes nasal demons, so anything goes. The language on the other hand…
@JSMuellerRoemer @lina I really don't understand this attitude. I'm getting the feeling that some compiler people read the C/C++ standards like the devil reads the bible.
@andreas @JSMuellerRoemer I learned today that, technically, the C standard can be interpreted as to make all kinds of valid code UB, because it defines "anything it doesn't define" as UB. And GCC exploits this in at least one case.
So unfortunately the "if the code is UB the compiler can legitimately do whatever it wants" argument doesn't really work, because a compiler that maximally exploits UB would be completely unusable for compiling any real program.
@JSMuellerRoemer @andreas Example: The C standard defines how function calls work, and declares that recursive function calls are valid. However, it says nothing about maximum recursion depth. Not even to say it's implementation defined. It is simply not mentioned, anywhere.
This means that platforms are free to implement any maximum recursion depth they wish, and they would still be compliant implementations. Further, exceeding this maximum may be legally declared UB. Implementations are not required to document any of this either.
The result is that, for example, GCC considers potential (but unproven) infinite recursion as unreachable UB.
@lina
Jason Turner covered this scenario in one of his weekly videos: https://youtu.be/atEP9wbuaL0?t=130