
Exploring undefined behavior using constexpr - matt_d
https://shafik.github.io/c++/undefined%20behavior/2019/05/11/explporing_undefined_behavior_using_constexpr.html
======
hellofunk
I’ve recently been writing just pure C and have been surprised by how much I
enjoy it. There are so many things about C++ that have remained confusing to
me, even though I’ve used it extensively over the years and have a lot of
respect for the language. But the simplicity not having to wrap my head around
all kinds of bizarre concepts that still confuse me in C++, I must say it’s
been a bit liberating of a feeling.

~~~
blub
I guess writing it can be fun, but managing it isn't. When I review C code I
have to spend 80% of my attention on figuring out if there's anything fishy
happening with memory. It's terrible how much C code is just memory-management
boilerplate.

------
saagarjha
This is a super interesting approach I hadn’t thought of. Unfortunately it
seems to be limited in practice, as demonstrated by the article: first of all,
certain constructs cannot be used in a constexpr context, and second (and more
worryingly) many compilers fail to diagnose undefined behavior or do so
incorrectly. If the second issue can be fixed I can see this being a very
useful, if specialized tool for improving the safety of C++ code.

~~~
bregma
> many compilers fail to diagnose undefined behavior or do so incorrectly.

It would be much easier if undefined behaviour was better defined, because
then a compiler could recognize it and diagnose it. Of course then it wouldn't
be undefined behaviour any more, so problem solved.

~~~
saagarjha
The bounds of what consists undefined behavior is, well, defined. The
“undefined” bit refers to the behavior in this case, not its ability to be
recognized.

