Q:

Initialization to same variable

I just found this as a mistype in my unit testing code:
Binding binding(x, y, z);
Binding moved(std::move(moved));  // Should be `std::move(binding)`

Why is this valid code? What is happening here? Shouldn't this be an error?
#include <string>
#include <iostream>

int main() {
    std::string x(std::move(x));
    std::cout << '"' << x << '"' << std::endl;
}

Compiled with gcc 4.8

A:

It's valid *(depending on the definition of Binding) because the name declared is known immediately from the point of declaration.
E.g.
struct Node { Node* next; int value; };

is one example of the same general principle, and
Node head = {&head, 0};

is a more direct example of a variable declaration using (or abusing) that idea.

*If the code invokes a usual move constructor that attempts to move from an uninitialized object, then that's Undefined Behavior, and invalid in that sense.

A:

Why is this valid code?

It isn't. It's syntactically valid, but has undefined behaviour (assuming the constructor uses its argument).

What is happening here?

Assuming the move constructor behaves as one would expect, moved is initialised using its own uninitialised value. Using an uninitialised value gives undefined behaviour.

Shouldn't this be an error?

Maybe, but it isn't. You can access a variable's name within its initialiser, which can be legitimate as long as you don't use the value. For example, this:
void * p = &p;

is well-defined, initialising a pointer to point to itself.
Since it's passed by reference to a user-declared constructor, the compiler can't tell whether or not the value might be used, and so can't issue a warning.

