<div dir="ltr">On Wed, Oct 9, 2013 at 3:56 PM, Arthur O'Dwyer <span dir="ltr"><<a href="mailto:arthur.j.odwyer@gmail.com" target="_blank">arthur.j.odwyer@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Wed, Oct 9, 2013 at 3:30 PM, Ted Kremenek <<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>> wrote:<br>

><br>
</div><div class="im">> template <int value> int sum() {<br>
</div>>   return value + sum<value/2>();<br>
<div class="im">> }<br>
><br>
> template<> int sum<1>() { return 1; }<br>
><br>
> template<int x, int y> int calculate_value() {<br>
>   if (x != y)<br>
>     return sum<x - y>();<br>
>   else<br>
>     return 0;<br>
> }<br>
><br>
> int value = calculate_value<1,1>();<br>
</div>[...]<br>
<div class="im">> Technically this should get folded out by the CFG builder.  It probably<br>
> doesn’t handle it yet, but it could easily be taught to handle this specific<br>
> case.  The CFG builder already prunes out some trivially unreachable paths.<br>
> This seems like one of those cases, since ‘x’ and ‘y’ are template<br>
> parameters.<br>
<br>
</div>FWIW, I would have thought that the implementation is *required* to<br>
instantiate sum<0> here, since it is implicitly instantiated by<br>
calculate_value<1,1> in this translation unit, and the implementation<br>
can't prove that sum<0> won't be required by an extern declaration in<br>
some other translation unit. I.e., I might link against a "foo.cc"<br>
containing<br>
<br>
    extern template int sum<0>(void);<br>
    void foo(bool b) { if (b) sum<0>(); }<br></blockquote><div><br></div><div>You can't rely on an implicit instantiation to satisfy an explicit instantiation declaration. If you use a specialization that is subject to an explicit instantiation declaration, there must be an explicit instantiation definition of that specialization somewhere in the program.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
However, I see that Clang (Apple's clang-425.0.28) actually already<br>
fails this test, so either it's permitted by the Standard or else<br>
Clang is already out of conformance in this area. I couldn't find any<br>
official language about "extern template", though.<br>
<span class="HOEnZb"><font color="#888888"><br>
–Arthur<br>
</font></span></blockquote></div><br></div></div>