3 ms·
Seems rad, but is this any different than providing `-S` to gcc or the equivalent option to your compiler of choice? Also, I assume the author has thought of t
by ZephyrP 12y ago
Seems rad, but is this any different than providing `-S` to gcc or the equivalent option to your compiler of choice?
Also, I assume the author has thought of this, but just throwing this out there....
`-ftemplate-depth1024` (1024 should guarantee a stack overflow)
#include <iostream>
template<int N>
struct ZVTemplate{
static void out(std::ostream& os)
{
ZVTemplate<N>::out(os);
os << "zv was here" << std::endl;
}
};
template<>
struct ZVTemplate<1>{
static void out(std::ostream& os)
{
os << "deftly evaded :)" << std::endl;
}
};
int main(){
ZVTemplate<2>::out(std::cout);
}
- mattgodbolt 12y agoI'm not quite sure what you were expecting to happen - here the template just recurses, but as a run-time recursion. GCC and the explorer handle it just fine. Doing the more usual template<N-1> trick lets you hit the -ftemplate-depth limit if you pass, for example ZVTemplate<2048>. It still works ok though :) Please do let me know if you can find a "poison" input...although at the moment the site is pretty busy just through sheer weight of users, so it's hard to tell I know! Thanks, Matt