Let's say I have the following function in a static library libutil (with the definition in one of the library's translation units, so it can't be inlined while compiling the caller's translation unit):
consteval int square(constexpr int x) {
return x * x;
}
And a function call in an executable hello which links against libutil:
int main() {
constexpr result = square(5);
printf("%d\n", result);
}
It was pointed out to me that C++ requires evaluation at "compile time", but with LTO some of the code generation is done at link time. Is this still considered "compile time" enough to do consteval evaluation? Is it compiler-dependent?
printf("%d\n", 25);and not leave any work to the linker. I also won't be surprised if the code forsquareisn't even present in the library at all.