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;
}
4
  • I'm pretty sure it's mandatory when the constexpr function is valid to be evaluated at compile-time. Commented Apr 1, 2013 at 21:09
  • It will work at compile time for f(2) but not likely for cin >> x; f(x);. Commented Apr 1, 2013 at 21:23
  • 1
    When does a constexpr function get evaluated at compile time? Commented Apr 1, 2013 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. Commented Apr 1, 2013 at 21:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.