←back to thread

In Defense of C++

(dayvster.com)
185 points todsacerdoti | 3 comments | | HN request time: 0.745s | source
Show context
lordleft ◴[] No.45267931[source]
Great article. Modern C++ has come a really long way. I think lots of people have no idea about the newer features of the standard library and how much they minimize footguns.
replies(2): >>45268114 #>>45268712 #
sunshowers ◴[] No.45268114[source]
Lambdas, a modern C++ feature, can borrow from the stack and escape the stack. (This led to one of the more memorable bugs I've been part of debugging.) It's hard to take any claims about modern C++ seriously when the WG thought this was an acceptable feature to ship.

Of course, the article doesn't mention lambdas.

replies(4): >>45268264 #>>45268485 #>>45268512 #>>45274413 #
1. account42 ◴[] No.45274413[source]
Not an issue if you make use of the tools available:

https://godbolt.org/z/xW14hGeoj

replies(1): >>45281570 #
2. sunshowers ◴[] No.45281570[source]
It looks like (a) this is a warning, not an error (why? the code is always wrong) and (b) the warning was added in clang 21 which came out this year. I also suspect that it wouldn't be able to detect complex cases that require interprocedural analysis.

The bug I saw happened a few years ago, and convinced me to switch to Rust where it simply cannot happen.

replies(1): >>45344411 #
3. 1718627440 ◴[] No.45344411[source]
A warning in C, C++ is the compiler saying "this is terribly broken, won't do what you want and I will exploit this". As opposed to an error, which means "I don't even know what you mean". Taking warnings lightly isn't the way to go in C or C++.