CppCon 2017: Louis Brandy “Curiously Recurring C++ Bugs at Facebook”
CppCon4 HN recommenders · recommended in 4 months, 2020–2025
talk · intermediate · evergreen · 2020–2025 on HN
Louis Brandy presents the most common and infamous recurring C++ bugs seen in Facebook's huge codebase, including shared_ptr data races and operator[] pitfalls. He explains the surprising complexity behind seemingly simple code.
HN recommends it as a must-watch catalogue of C++ footguns, often cited in debates about Rust and C++ safety.
Up next
3 mo on HNWild Tricks for Greenscreen in Blender
IanHubert
3 HN recommender · 2020–2026
3 mo on HNBlender Motion Tracking - Room Transformation!
IanHubert
4 HN recommender · 2020–2022
2 mo on HNCppCon 2017: Herb Sutter “Meta: Thoughts on generative C++”
CppCon
2 HN recommender · 2017–2020
5 mo on HNBut what is the Riemann zeta function? Visualizing analytic continuation
3Blue1Brown
6 HN recommender · 2017–2023
6 mo on HNCppCon 2015: Greg Law " Give me 15 minutes & I'll change your view of GDB"
CppCon
6 HN recommender · 2018–2023
7 mo on HNCppCon 2014: Chandler Carruth "Efficiency with Algorithms, Performance with Data Structures"
CppCon
7 HN recommender · 2014–2024
3 mo on HNHow wildlife trade is linked to coronavirus
Vox
5 HN recommender · 2020–2020
3 mo on HNHow Does SHA-256 Work?
learnmeabitcoin
3 HN recommender · 2020–2022
11 mo on HNCppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
7 HN recommender · 2017–2025
12 mo on HNLexical Scanning in Go - Rob Pike
GoogleFOSSSydney
13 HN recommender · 2012–2025
10 mo on HNCppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
CppCon
9 HN recommender · 2018–2026
9 mo on HNRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
9 HN recommender · 2018–2023
5 comments from Hacker News
No. Sorry for being unclear. [1] is a great video that covers a lot of good stuff in particular this usability bug. It's worth watching in its entirety. If you don't want to sit through the video, here's the broken code in question: void Obj::update() noexcept { unique_lock<mutex>(m_mutex); do_the_mutation(); } "unique_lock<mutex>(m_mutex);" has no effect, but you might mistakenly think that this will block on m_mutex. Labeling unique_lock's constructor as [[nodiscard]] would force you to think twice. See [2] for more details. [1] ▶ this video [2] link
Unfortunately, operator[] on std::vector is inherently unsafe. You can potentially try to ban it (using at() instead), but that has its own problems. There’s a great talk by Louis Brandy called “Curiously Recurring C++ Bugs at Facebook” [0] that covers this really well, along with std::map’s operator[] and some more tricky bugs. An interesting question to ask if you try to watch that talk is: How does Rust design around those bugs, and what trade offs does it make? [0]: ▶ this video
There are many differences when it comes to safety: - Like you said, Rust doesn't let you data race on the contents of an Arc. - Rust also doesn't let you data race on the Arc itself (i.e. repointing a global Arc without synchronization). This is Bug #5 in this great talk: ▶ this video - Rust also doesn't let you retain a reference to the contents of an Arc longer than you retain the Arc. This is the bug that C++ Core Guideline R.37 is about: link But I'm not sure I'd call these Arc vs shared_ptr differences per se, because almost any comparison between a Rust container and its C++ equivalent looks similar.
I'm a big fan of Scott Meyer's Effective C++ . It's a little dated now, but it was the most valuable book I'd ever read on the language. Louis Brandy's Curiously Recurring Bugs at Facebook presentation from CppCon17 has somewhat of the same feeling, though it only covers a few bugs: ▶ this video
The point of the article isn't that single-threaded non-atomic shared pointers are unfeasible in C++, it is that their usage is too dangerous. The fact that it wasn't included in the standard library for this reason is an argument for this. The fact that even `shared_ptr` has thread-safety footguns, one of which made it to the famous C++ talk, “Curiously Recurring C++ Bugs at Facebook”[1], is another. By the way, every single of the bugs from that talk is impossible in safe Rust. [1]: ▶ this video