My favourite C++ footgun
My (least) favorite footgun is "auto" when it comes to references.<p>If you want to get a pointer from something, you would write this:<p><pre><code>    auto fooPtr = mywidget.getPtr();
    fooPtr->doCoolStuff();
</code></pre>
But we all know references are better than pointers right? So we should just write...<p><pre><code>   auto fooRef = myWidget.getRef();
   fooRef.doCoolStuff()
</code></pre>
The problem is... this is valid and will probably not do what you want. It will make a copy. What you want is actually<p><pre><code>   auto& fooRef = myWidget.getRef();
</code></pre>
I once spent an entire day debugging a bizarre crash because of that. I was asking for a reference to a scene graph, and what was actually happening is I was getting a clone of the scene graph (which was an object that couldn't be safely copied), and then destroying a bunch of shared pointers when the function returned. Fun times.