Using reference as template type
<p>In the following example, <code>Foo</code> is not doing what is intended, but I can't figure out why this is allowed to compile.</p>

<pre><code>#include &lt;string&gt;
#include &lt;iostream&gt;

typedef std::string&amp; T;

T Foo(int &amp; i)
{
    return T(i);
}

int main()
{
    int a = 1;
    std::string &amp; s = Foo(a);
}
</code></pre>

<p>I discovered this with templates, but the <code>typedef</code> shows that its unrelated to templates.  Needless to say, <code>s</code> is not a valid string here.  I would think that constructing the value in the return of <code>Foo</code> would produce a compile error.</p>

<p>What am I missing here?</p>
