On Wed, Oct 9, 2013 at 3:30 PM, Ted Kremenek <[email protected]> wrote:
> On Oct 9, 2013, at 1:03 PM, Richard Trieu <[email protected]> wrote: > > Here is the code in question, template parameters fixed now: > > 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>(); > > calculate_value<1,1>() causes the instantiation of sum<0>(), even though > it is protected from being called by the conditional "if (x != y)". > sum<0>() is the only self-recursive function here. Are you saying we > should warn on that even though the programmer added the proper check to > prevent it from being called? > > > 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. > I don't think that helps. sum<0> is still used, so we still instantiate it, and when we check its definition we would diagnose the infinite recursion.
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
