Files
linux-kernel-module-cheat/userland/cpp/constexpr_func_infinite_loop.cpp
Ciro Santilli 六四事件 法轮功 d09a0d97b8 learn more c++, it never ends
2020-03-19 00:00:00 +00:00

23 lines
547 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// https://cirosantilli.com/linux-kernel-module-cheat#cpp
constexpr int f() {
int i = 0;
while (1)
i += 1;
return i;
}
constexpr int g() {
return g();
}
int main() {
#if 0
// GCC 9.2.1. error: constexpr loop iteration count exceeds limit of 262144 (use -fconstexpr-loop-limit= to increase the limit)
static_assert(f() == 0);
// GCC 9.2.1. error: constexpr evaluation depth exceeds maximum of 512 (use -fconstexpr-depth= to increase the maximum)
static_assert(g() == 0);
#endif
}