|
|
|
|
|
by tsimionescu
1167 days ago
|
|
Yes, but that error would simply complain that a variable that doesn't have a compile time known value is been used in a compile time context. Conversely, the origin of the thread implies that if a function has been successfully called with some argument from a static_assert, it will not have UB at runtime even if called with some other arguments. This subthread was showing that this is not the case, and that you can't test all uses of a function using static_assert to guarantee that it will not exhibit UB. In case it's not clear, this piece of code will also fail to compile, even though it exhibits no UB: constexpr int foo(int y) {
return y;
}
int y;
std::cin>>y;
static_assert(foo(y));
https://godbolt.org/z/xvhP8nq7z |
|