Jason Merrill
2010-03-12
N3078=10-0068

Constexpr functions with reference parameters

This wording is revised from the wording in N3039 by Bjarne Stroustrup, Alisdair Meredith and Gabriel Dos Reis; please see that paper for rationale. The changes in this document are primarily to broaden the allowance to non-const references. Any problematic operation on a non-const reference is still prohibited because it would prevent the function body from being a potential constant expression.

Proposed wording

7.1.5/3, second and third bullets:
7.1.5/4, first bullet:
5.19/2, third bullet:
5.19/2, bullets 6-9:
5.19/6: An expression is a potential constant expression if it is a constant expression when all occurrences of function parameters are replaced as follows:
  • for non-reference parameters, by arbitrary prvalue constant expressions of the appropriate types;
  • for lvalue reference parameters, by arbitrary variables of the referred-to types with static storage duration initialized with constant expressions; or
  • for rvalue reference parameters, by arbitrary prvalue constant expressions of the referred-to types implicitly converted to the types of the parameters.
  • 7.1.5:
    If the instantiated template specialization of a constexpr function template would fail to satisfy the requirements for a constexpr function or constexpr constructor, the constexpr specifier is ignored.

    A call to a constexpr function produces the same result as a call to an equivalent non-constexpr function in all respects except that a call to a constexpr function can appear in a constant expression.