Can you copy a member of an object that’s passed by reference?

Consider below code,

void handleConnection(Connection &connection) {
    // std::vector
    auto messages = connection->messages;

    // Do Work


Why does assigning connection->messages to auto messages creates a copy without implicitly creating a reference?

The main reason I asked this question is because I noted the above code causing duplicate messages and that means it makes a copy, but I cannot find a law in the C ++ standard that describes this.


The rules for auto state that the following code:

auto x = y;

will always make a copy of y, and deduce the type of x to be the same as y. Whether y is a member of an object that you’re holding a reference to, is completely irrelevant.


auto &x = y;

will make x a reference to y, with the same type. Whether y is a member of an object of which you have a copy or a reference, doesn’t affect this at all.