https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85747
--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> --- (In reply to Antony Polukhin from comment #0) > Could the compiler detect that `a[7]` holds values known at compile time and > force the constexpr on `sort(a + 0, a + 7);`? There has to be a limit. If I write a program that computes the trillion's decimal of pi, this is a constant, do you expect the compiler to evaluate the whole program and compile it to just return cst? We are moving into a realm where we would want to mix compilation and execution, sort of JIT. For smaller functions, some heuristics could be used to try compile-time evaluation, but sorting an array of size 7 already seems large to me. > Could the compiler detect that > the function `generate()` is an `__attribute__((const))` function without > arguments and fully evaluate it's body? If you call the function twice in a row, the compiler removes the second call and reuses the result from the first, so at least it notices that generate is pure.