The C++ fundamentals your seniors think they know -- Mateusz Pusz
Pointer provenance, the One Definition Rule, name lookup, and move semantics are not beginner topics. They are the load-bearing rules that decide whether code which compiles is actually correct. This is the opening article of a series on the ones experienced C++ developers most often get wrong, each post opening on a failure that reached production.
The C++ fundamentals your seniors think they know
by Mateusz Pusz
From the article:
Here is a five-second test. Ask an experienced C++ developer what
new Connection{host}does, given a constructor that can throw. Almost everyone says “it callsoperator new.” Almost no one names the new-expression: the language construct that first callsoperator newto obtain raw storage and then constructs the object in it, two separate steps that the one keyword hides.That gap is not trivia. It is why people write an
operator newthat tries to construct the object, cannot say who does the construction ifoperator newdoes not, cannot say who frees the storage when the constructor throws, and get caught out by placementnew. The rule was there the whole time. Nobody ever pointed at it.
Published so far: