1

Consider the only cases in which it is possible for the compiler to evaluate a constexpr function at compile-time. In these cases, it's not clear from the standard (paragraph 5.19) whether it is always mandatory for the compiler to evaluate constexpr functions at compile-time or not; if it is not always mandatory, I would eventually like to see some examples where the standard does give strong guarantees about compile-time evaluations of constexpr functions.

constexpr int f(int n) {
   return n*n;
}
Martin
  • 9,089
  • 11
  • 52
  • 87
  • I'm pretty sure it's mandatory when the `constexpr` function is valid to be evaluated at compile-time. – chris Apr 01 '13 at 21:09
  • It will work at compile time for `f(2)` but not likely for `cin >> x; f(x);`. – Bo Persson Apr 01 '13 at 21:23
  • 1
    [When does a constexpr function get evaluated at compile time?](http://stackoverflow.com/questions/14248235/when-does-a-constexpr-function-get-evaluated-at-compile-time?rq=1) – Bo Persson Apr 01 '13 at 21:30
  • Thanks BO, I think the "When does a constexpr function get evaluated at compile time?" answered question better answers to my question too, the other one being not really clear in one case. – Martin Apr 01 '13 at 21:36

0 Answers0