161. Sanitizers, Cpp2, exceptions, compilers
With Bjarne Stroustrup, Frances Buontempo, Gianluca Delfino, Vladimír Arnošt, Andrew Fodiman and other colleagues.
Media
Video
Podcast
Powered by RedCircle
Book: C++ Bookcamp
Updated with Chapter 6: Smart pointers and polymorphism
East const!
The Overload Journal 174 (April 2023)
Do expressions: progress
P2806R1 was discussed in EWG. Polls:
- EWG encourages more work in the direction of do-expressions as presented in P2806R1 => Consensus.
- EWG prefers the “result” of the do-expression be ’last statement’, ala GCC statement-expressions, prohibiting early-return from a do-expression. => Consensus against.
Good!
Sanitizers and compiler optimizations
TL;DR: Run sanitizers with -O0
to achieve the best bug detection rate.
See also: All about sanitizer interceptors, by Fangrui Song.
Cpp2 Spring update
Previously:
Herb Sutter: Cpp2 is to C++ as Swift is to Objective-C.
It’s still C++ even if the syntax is different.
Hmm. Looks like a different language to me.
It’s just a personal experiment.
Lots of contributors, lots of enthusiasm and big expectations.
It’s really simple.
He said it! It means it’s never simple.
You can mix Cpp2 and C++ entity by entity in the same source file.
A colon always means I’m declaring a new thing and it has no other meaning.
Herb’s proposals in the last 7 years came from Cpp2 work.
Regarding Vittorio Romeo’s Epochs proposal, Herb says it could be just a single Epoch that introduces a breaking change, as this is once-in-30-years opportunity. Presumably this is what he thinks about Cpp2?
Exceptions again
The author thinks that if exceptions were truly zero-cost, they would be using exceptions everywhere, including function precondition checking, which is not ideal (see also C++ Contracts, which we don’t have yet).
In most cases, don’t worry about the cost of exceptions. But don’t throw thousands of exceptions in quick succession either.
Embedded platforms are a special case (no heap, or hard no-throw requirements).
Microsoft: Modern C++ best practices for exceptions and error handling
GCC 13.1 released
The C frontend got support for several C23 features, the C++ frontend for C++23 features. The C++ standard library experimental support for C++20 and C++23 was enhanced.
Still no modules. C++20 support is experimental.
GCC 13 will have <format>
Great news! Until then, use {fmt}.
My favorite C compiler flags during development, by Chris Wellons
match(it)
A lightweight header-only pattern-matching library for C++17 with macro-free APIs.
Clang 16 released
Previously: Clang 15 released
Soon: modules in Clang 17
Boost 1.82 released
See also:
Since C++11, Boost has shifted from “provide actually useful basic containers because the STL is shit” to “provide cool, quality stuff that is widely useful but out of scope for the STL”. See e.g. Flyweight, Spirit, Log, Multiprecision, Safe Integer, Asio. Boost is still a wonderful library collection. ↑
A General Overview of What Happens Before main()
See also: CppCon 2018: Matt Godbolt “The Bits Between the Bits: How We Get to main()”
Operator new
sounds better
- Dan Ports on Mastodon:
This is your periodic reminder that 10 years ago an audiophile forum started debating which versions of
memcpy
had the highest sound quality. And that C++new
sounds better thanmalloc
.
found that a function called memcpy was the culprit, most memory players use memcpy and this is one of the reasons why memory play sounds worse ie digital sounding. Fortunately there is an optimised version of memcpy from http://www.agner.org/optimize/, using this version removes the hard edge produced by memcpy. the other thing I did was to close the file after reading into the buffer.
also most players use malloc to get memory while new is the c++ method and sounds better.
But wait! It may not be that simple!
Mastodon
The worst thing that ever happened in software engineering was when Kirk asked Scotty how long something would take and Scotty said thirty minutes and Kirk said you’ve got five and Scotty got it done in five and impressionable children watched this and grew up to become managers.