learn more c++, it never ends

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-03-19 00:00:00 +00:00
parent 082166a360
commit d09a0d97b8
6 changed files with 277 additions and 29 deletions

View File

@@ -0,0 +1,22 @@
// 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
}