|
|
|
|
|
by simiones
1168 days ago
|
|
That only works if you know the values at compile-time though: constexpr int foo(int x) {
return 1024*1024*1024*x;
}
int main()
{
int y;
std::cin >> y;
static_assert(foo(1)); //all good
foo(y); //oops, UB if user enters 7
}
https://godbolt.org/z/K8h4Kj99sEdit: small correction so that the numbers are big enough to cause problems... |
|