<p dir="auto">In the following program:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import &quot;fmt&quot;

func main() {
    const A = 0xfffffffffffffffff // error
    // const A = 0x8000000000000000 // error
    // const A = 0x7fffffffffffffff // ok
    a := string(A)
    for i, r := range a {
        fmt.Printf(&quot;%d: %x\n&quot;, i, r)
    }
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> <span class="pl-s">"fmt"</span>

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
    <span class="pl-k">const</span> <span class="pl-s1">A</span> <span class="pl-c1">=</span> <span class="pl-c1">0xfffffffffffffffff</span> <span class="pl-c">// error</span>
    <span class="pl-c">// const A = 0x8000000000000000 // error</span>
    <span class="pl-c">// const A = 0x7fffffffffffffff // ok</span>
    <span class="pl-s1">a</span> <span class="pl-c1">:=</span> <span class="pl-en">string</span>(<span class="pl-s1">A</span>)
    <span class="pl-k">for</span> <span class="pl-s1">i</span>, <span class="pl-s1">r</span> <span class="pl-c1">:=</span> <span class="pl-k">range</span> <span class="pl-s1">a</span> {
        <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"%d: %x<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">i</span>, <span class="pl-s1">r</span>)
    }
}</pre></div>
<p dir="auto">The compiler issues error message <code class="notranslate">overflow in int -&gt; string</code>.</p>
<p dir="auto">Form the Go Spec <a href="https://golang.org/ref/spec#Conversions" rel="nofollow">https://golang.org/ref/spec#Conversions</a></p>
<blockquote>
<p dir="auto">A constant value x can be converted to type T in any of these cases:</p>
<ul dir="auto">
<li>x is an integer constant and T is a string type. The same rule as for non-constant x applies in this case.</li>
</ul>
</blockquote>
<p dir="auto">...</p>
<blockquote>
<p dir="auto">A non-constant value x can be converted to type T in any of these cases:</p>
<ul dir="auto">
<li>x is an integer or a slice of bytes or runes and T is a string type.</li>
</ul>
</blockquote>
<p dir="auto">...</p>
<blockquote>
<p dir="auto">Conversions to and from a string type</p>
<ol dir="auto">
<li>Converting a signed or unsigned integer value to a string type yields a string containing the UTF-8<br>
representation of the integer. Values outside the range of valid Unicode code points are converted to<br>
"\uFFFD".</li>
</ol>
</blockquote>
<p dir="auto">According to the above, the conversion should succeed, with the resulting string containing the UTF-8 encoding of <code class="notranslate">0xfffd</code>.</p>
<p dir="auto"><code class="notranslate">gccgo</code> does not issue an error and behaves as in the spec.</p>
<p dir="auto">Gc rejects to compile the following program:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package a
var a = string(9223372036854775808)"><pre class="notranslate"><span class="pl-k">package</span> a
<span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-en">string</span>(<span class="pl-c1">9223372036854775808</span>)</pre></div>
<p dir="auto">saying:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="overflow in int -&gt; string"><pre class="notranslate"><code class="notranslate">overflow in int -&gt; string
</code></pre></div>
<p dir="auto">go/types compile it successfully.</p>
<p dir="auto">Compilers must agree on whether it is a valid Go program or not.</p>
<p dir="auto">on commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/golang/go/commit/af817890aa7b628234075a6cb01a3a435fb8317d/hovercard" href="https://github.com/golang/go/commit/af817890aa7b628234075a6cb01a3a435fb8317d"><tt>af81789</tt></a></p>