Negative numeric string (e.g. "-10") to unsigned short
<p>Code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;algorithm&gt;
using std::cerr;
using std::cout;
using std::stringstream;
using std::string;
using std::for_each;

void convert(const string&amp; a_value)
{
    unsigned short i;
    if (stringstream(a_value) &gt;&gt; i)
        cout &lt;&lt; a_value &lt;&lt; " converted to " &lt;&lt; i &lt;&lt; ".\n";
    else
        cerr &lt;&lt; a_value &lt;&lt; " failed to convert.\n";
}

int main()
{
    string inputs[] = { "abc", "10", "999999999999999999999", "-10", "0" };
    for_each(inputs, inputs + (sizeof(inputs)/sizeof(inputs[0])), convert);
    return 0;
}
</code></pre>

<p>Output from Visual Studio Compiler (v7, v8, v9, v10):</p>

<pre>
abc failed to convert.
10 converted to 10.
999999999999999999999 failed to convert.
-10 converted to 65526.
0 converted to 0.
</pre>

<p>Output from g++ (v4.1.2, <a href="http://ideone.com/T2sMF3">v4.3.4</a>):</p>

<pre>
abc failed to convert.
10 converted to 10.
999999999999999999999 failed to convert.
-10 failed to convert.
0 converted to 0.
</pre>

<p>I expected the <code>"-10"</code> to fail to be converted to an <code>unsigned short</code> but it succeeds with the VC compilers. Is this a:</p>

<ul>
<li>bug in the VC compilers ?</li>
<li>bug in the GNU compilers and I have an incorrect expectation ?</li>
<li>an implementation defined behaviour ?</li>
</ul>
