Is it well-defined to take reference of an R-value reference

Viewed 31

In a function taking an R-value reference, is it well-defined if we take its reference? For example:

void foo(int &&i) {
    cout << &i << endl;
}
int main() {
    int i = 1;
    cout << &i << endl;
    foo(std::move(i));
    return 0;
}

Both cout print the same value, but is it well-defined or undefined?

Or like this:

void foo(int &&i) {
    cout << &i << endl;
}
int main() {
    foo(1);
    return 0;
}

cout prints some address, but is it valid (not pointing any existing object) or just random value?

0 Answers
Related