On 5/6/13 11:31 AM, Andrei Alexandrescu wrote:
struct A { A(const T& x) : a(x) {} const T& a; };In _this_ case, initializing A with an rvalue of type T compiles and subsequently runs with undefined behavior.
I should add I've seen this bug several times (causing mysterious crashes) several times at Facebook. We're working on adding a lint rule to disable the pattern statically.
Binding rvalues to references is fraught with peril. Andrei