I'm interested to know whether this is strictly legal and if so why. Could it be a bug in GCC? Surely not?

Code:
#include <iostream>
using namespace std;

class A;

void Foo(A& a);

struct A
{
    int x;
};

int main()
{
    A a;
    a.x = 3;
    Foo(a);
    return 0;
}

void Foo(A& a)
{
    cout << a.x << endl;
}