Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Clang is being inconsistent. <a href="http://coliru.stacked-crooked.com/a/94b4b1df122762ce">Since it accepts your code</a>, I'm expecting the following code must output <code>f(Int&lt;long long&gt;)</code> instead of <code>f(T)</code>:</p> <pre><code>using IntType = unsigned long long; template &lt;IntType N&gt; struct Int {}; template&lt;typename T&gt; void f(T) { std::cout &lt;&lt; "f(T)" &lt;&lt; std::endl; } template&lt;long long N&gt; void f(Int&lt;N&gt;) { std::cout &lt;&lt; "f(Int&lt;long long&gt;)" &lt;&lt; std::endl; } int main() { f(Int&lt;0&gt;{}); } </code></pre> <p>But surprisingly, it outputs this (<a href="http://coliru.stacked-crooked.com/a/0ad6a48e90adeb1d">online demo</a>):</p> <pre><code>f(T) </code></pre> <p>That shows <code>Int&lt;0&gt;</code> does NOT match with the second overload which accepts the argument as <code>Int&lt;N&gt;</code>. If that is so, then why does it match with <code>Int&lt;N&gt;</code> when it is used as template argument to the class template (in your case)?</p> <p>My conclusion:</p> <ul> <li>If Clang is correct in <strong>my</strong> case, then it is incorrect in <strong>your</strong> case.</li> <li>If Clang is correct in <strong>your</strong> case, then it is incorrrect in <strong>my</strong> case.</li> </ul> <p>Either way, Clang seems to have bug.</p> <p>GCC, on the other hand, is consistent at least. That doesn't prove though that it doesn't have bug &mdash; it might mean that it has bug in both cases! Unless someone comes up with the standardese and showing it has bug <em>too</em>, I'm going to trust GCC in this case.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload