On Wed, Oct 9, 2013 at 3:56 PM, Arthur O'Dwyer <[email protected]>wrote:
> On Wed, Oct 9, 2013 at 3:30 PM, Ted Kremenek <[email protected]> wrote: > > > > template <int value> int sum() { > > return value + sum<value/2>(); > > } > > > > template<> int sum<1>() { return 1; } > > > > template<int x, int y> int calculate_value() { > > if (x != y) > > return sum<x - y>(); > > else > > return 0; > > } > > > > int value = calculate_value<1,1>(); > [...] > > Technically this should get folded out by the CFG builder. It probably > > doesn’t handle it yet, but it could easily be taught to handle this > specific > > case. The CFG builder already prunes out some trivially unreachable > paths. > > This seems like one of those cases, since ‘x’ and ‘y’ are template > > parameters. > > FWIW, I would have thought that the implementation is *required* to > instantiate sum<0> here, since it is implicitly instantiated by > calculate_value<1,1> in this translation unit, and the implementation > can't prove that sum<0> won't be required by an extern declaration in > some other translation unit. I.e., I might link against a "foo.cc" > containing > > extern template int sum<0>(void); > void foo(bool b) { if (b) sum<0>(); } > 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. > However, I see that Clang (Apple's clang-425.0.28) actually already > fails this test, so either it's permitted by the Standard or else > Clang is already out of conformance in this area. I couldn't find any > official language about "extern template", though. > > –Arthur >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
