Reputation: 1483
Does there exist such kind of compile-time computation that can get compilers into endless loop?
May the endless loop not consume increasing memory? Or it may stop for the lack of memory.
Upvotes: 0
Views: 86
Reputation: 35512
There are infinite loops just like in run-time, however unlike run-time, the compiler will stop after enough iterations. Here's an example:
#include <iostream>
template<int i>
struct loop {
// this will just keep referencing itself
static constexpr int val = loop<i + 1>::val;
};
int main() {
std::cout << loop<0>::val << std::endl;
}
The compiler gives the following error message:
fatal error: template instantiation depth exceeds maximum of 900
Upvotes: 5