mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 10:15:57 +01:00
learn more c++, it never ends
This commit is contained in:
22
userland/cpp/constexpr_func_infinite_loop.cpp
Normal file
22
userland/cpp/constexpr_func_infinite_loop.cpp
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user