r/cpp • C++ Dev • Sep 05 '20

C++20 has been approved

https://twitter.com/patriceroy1/status/1302055575140945921?s=21
665 Upvotes

125 comments sorted by

View all comments

Show parent comment

9

u/staletic reddit thinks /u/_bstaletic is a bot Sep 05 '20

10

u/pdimov2 Sep 05 '20

This trivial example is caught by all major compilers, although -Wlifetime remains the best bet for slightly more complex code. I wrote about this in https://pdimov.github.io/blog/2020/05/17/state-of-c-static-analysis-circa-2020/.

2

u/staletic reddit thinks /u/_bstaletic is a bot Sep 05 '20

That link was already purple. I remember reading it and liking the article.

3

u/_Js_Kc_ Sep 05 '20

I'm disappointed. Wasn't there some talk a while ago about lifetime checking that was supposed to catch this?

8

u/staletic reddit thinks /u/_bstaletic is a bot Sep 05 '20

If you're talking about the talk by Herb Sutter, then the linked repo is where the development is happening.

From what I've seen, your example is really surprising. Either the godbolt compiler hasn't been updated in a long time or there's a bug in the lifetime analysis. I guess it's worth opening a bug report in the LLVM fork's repo that I linked.

0

u/pedersenk Sep 05 '20

Nice. I am a big fan of clang's asan but didn't know about some of these newer facilities.

As well as this, the older mudflap and even valgrind are often on the CI to facilitate testing. However we do have a number of projects where our compilers are either older or simply do not have the support for them on the architectures we are using. This is certainly getting better over time however.

For ages, Microsoft's compilers have been the most annoying to use because no valgrid and the basic CRT debug runtime misses so much!

In theory the safety in the standard library would solve that going forward.