[cfe-dev] Endless recursion due to return type deduction of mutually-recursive templates
Yaron Keren
yaron.keren at gmail.com
Thu Sep 19 01:34:43 PDT 2013
Hello,
The following code causes endless recursion leading to seg fault with the
latest SVN.
clang tries to deduce g return type, which requires f return type, which
requires g return type, repeats endlessly.
If the templates are modified to regular functions taking double, clang
correctly errors upon parse:
error: function 'g' with deduced return type cannot be used before it is
defined
return x*g(x-1);
but with templates there is no error parsing, just seg fault running.
Yaron
// Endless recursion with revision 190992.
template <class T>
auto g(T x);
template <class T>
auto f(T x) {
if (x>0)
return x*g(x-1);
else
return 1.0;
}
template <class T>
auto g(T x) {
if (x>0)
return x*f(x-1);
else
return 1.0;
}
int main() {
f(9.0);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130919/a8cffa4d/attachment.html>
More information about the cfe-dev
mailing list