|
Jason Turner
@
lefticus
Colorado, USA
|
|
CppCast.com co-host, cppbestpractices.com curator, chaiscript.com, C++ Weekly youtube.com/c/JasonTurner-…
he/him
|
|
|
9.959
Tweetovi
|
506
Pratim
|
9.895
Osobe koje vas prate
|
| Tweetovi |
|
Jason Turner
@lefticus
|
3 h |
|
/Wall isn't recommended by microsoft and their stdlib isn't clean with it, so /W4 + things on MSVC
-Weverything maybe on clang if I can tolerate it with a few things disabled.
github.com/lefticus/cppbe…
|
||
|
|
||
|
Jason Turner
@lefticus
|
5 h |
|
I'm pretty strict about it. Tests with good coverage, CI running with sanitizers, *all* warnings turned on, cppcheck, clang-tidy, etc.
All of those things passing without warning
|
||
|
|
||
|
Jason Turner
@lefticus
|
5 h |
|
Personally, "Time To Market" or "Seeing Something Usable" is probably my very initial concern. I want to know what the road I'm going down makes sense, is viable, and is fun to play with. Then I very quickly want to switch to correctness.
|
||
|
|
||
|
Jason Turner
@lefticus
|
8 h |
|
the strict aliasing warning tools are not as good as I would like from gcc et al
|
||
|
|
||
|
Jason Turner
@lefticus
|
9 h |
|
That example of mine was specifically in response to a question about how code can appear to work but be incorrect on closer examination
|
||
|
|
||
|
Jason Turner
@lefticus
|
9 h |
|
Accessing an object after its lifetime has ended is in no way a strawman. You could argue it's slideware and over simplified, but it's the class of bug people deal with every day.
If the memory has not yet been reused, it will appear to work.
|
||
|
|
||
|
Jason Turner
@lefticus
|
11 h |
|
Example: godbolt.org/z/CRYzBI
Only an optimized build on GCC exposes the UB. Only an optimized build on GCC gives you the appropriate warning.
All cases are UB. The code appears to work. It's subject to breaking with different versions of different compilers.
|
||
|
|
||
|
Jason Turner
@lefticus
|
11 h |
|
Code that contains undefined behavior will appear to work in some situations and fail in others.
Example: it may rely on the debugger default initializing values, or it may rely on objects being eliminated by the optimizer, all accidentally.
|
||
|
|
||
|
Jason Turner
@lefticus
|
11 h |
|
Much code appears to work but on closer inspection does not actually.
|
||
|
|
||
|
Jason Turner
@lefticus
|
11 h |
|
I'll have to admit I haven't followed the entire conversation but I know without doubt that this is correct
int i;
int &i_ref = i;
std::cout << i_ref; // UB (read of uninitialized value)
i = 42; // not UB (write to uninitialized value)
std::cout << i_ref; // not UB (init now)
|
||
|
|
||
|
Jason Turner
@lefticus
|
12 h |
|
cast-to-void (I believe) is guaranteed to be a no-op. Void types have no lifetime so it's impossible to invoke any kind of constructor/copy/etc.
|
||
|
|
||
|
Jason Turner
@lefticus
|
12 h |
|
Perhaps some people see beauty in correctness?
|
||
|
|
||
|
Jason Turner
@lefticus
|
12 h |
|
Indeed.
One of my favorite classes to teach involves *many* exercises around the order of construction/destruction/lifetime of objects.
One of the things that makes statics annoying is the difficulty in knowing if their lifetime has begun yet or not and in what order.
|
||
|
|
||
|
Jason Turner
@lefticus
|
12 h |
|
More to the point, if its lifetime hadn't begun you couldn't assign to it.
|
||
|
|
||
|
Jason Turner
@lefticus
|
12 h |
|
Came here to add this comment, you beat me to it
|
||
|
|
||
|
Jason Turner
@lefticus
|
12 h |
|
Yes, as far as I know always existed as well.
|
||
|
|
||
|
Jason Turner
@lefticus
|
14 h |
|
Never used in production as far as I know, but @ben_deane and I implemented a constexpr json parser in 2017.
youtu.be/HMB9oXFobJc
github.com/lefticus/const…
|
||
|
|
||
|
Jason Turner
@lefticus
|
14 h |
|
I believe std::less also qualifies because of its ability to compare pointers into different objects?
|
||
|
|
||
|
Jason Turner
@lefticus
|
14 h |
|
What do you do?
|
||
|
|
||
|
Jason Turner
@lefticus
|
14 h |
|
Maybe I should do another poll:
* Beautiful Code
* Readable Code
* Maintainable Code
* Clever Code.
Just to see people's perceptions
|
||
|
|
||