Can an lvalue at the end of a region be treated as an rvalue?

EDIT: Consider the following two examples:

std::string x;
{
    std::string y = "extremely long text ...";
    ...
    x = y; // *** (1)
}
do_something_with(x);

struct Y
{
    Y();
    Y(const Y&);
    Y(Y&&);
    ... // many "heavy" members
};

struct X
{
    X(Y y) : y_(std::move(y)) { }
    Y y_;
}

X foo()
{
    Y y;
    ...
    return y; // *** (2)
}

In both examples yin lines (1) and (2), the end of his lifetime is near and is about to be destroyed. It seems obvious that it can be thought of as an rvalue and moved around in both cases. In (1), its contents can be moved to xand in (2) to a temporary instance X().y_.

My questions:

1) Will it be moved in any of the above examples? (a) If so, in accordance with which standard provision. (b) If not, why not? Is this an omission in the standard or is there another reason I don’t think about?

2) . (1) x = std::move(y), . , , y ? return std::move(y)?

NB: y, x (2), (N) RVO.

+6
2

"". , ( ) . , std::string "", , - , as-if. , , - :

struct foo {
    foo(foo const &f) { std::cout << "copy ctor\n"; }
    foo(foo &&f) { std::cout << "move ctor\n"; }
};

foo outer;
{ 
    foo inner;
    // ...
    outer = inner;
}

... , "copy ctor", "move ctor". - , , , , .

, : , , . , . , , , , , - .

, , - , .

(N4659, § [class.copy.elision]/3):

- :

  • return (9.6.3) (, ) id-, , -- - ,

[...]

, rvalue. , rvalue (, cv-qualified), , .

(y) return id-, , , .

, , X y. X ( ) , y . , , "" . , , y rvalue, , X ctor .

, X - :

struct X
{
    X(Y &&y);
    X(Y const &y); 

    Y y_;
}

... , ​​ - y lvalue, rvalue, X(Y &&y) X, , .. ( y lvalue, , lvalue).

+8

outer ? &outer. *inner.

-3

All Articles