On Tuesday, 20 December 2016 at 19:24:32 UTC, Ali Çehreli wrote:
As a general rule, 'auto ref' should probably be const. If the purpose of 'ref' is so that the argument would be mutated, then allowing a copy of an rvalue to this function could very well be a bug:

struct S {
    int i;
}

void foo()(auto ref S s) {
    s.i = 42;  // <-- Cannot be observed if the arg is rvalue
}

void main() {
    foo(S(1));
}

Thank you Ali! This is effectively a trap I had not realized, you probably save me from some long debugging time.

Reply via email to