Rvalue references - The resolution

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon May 6 08:32:54 PDT 2013


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



More information about the Digitalmars-d mailing list