This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


1099. Infinite recursion in constexpr functions

Section: 7.7  [expr.const]     Status: C++11     Submitter: Jason Merrill     Date: 2010-08-01

[Voted into the WP at the March, 2011 meeting.]

It is not clear what happens when a program violates the limits on constexpr function recursion in a context that does not require a constant expression. For example,

  constexpr int f(int i) { return f(i); }
  const int i = f(1);   // error, undefined behavior, or dynamic initialization?

(Presumably the “within its resource limits” caveat of 4.1 [intro.compliance] paragraph 2 would effectively result in undefined behavior in a context that required a constant expression.)

Notes from the November, 2010 meeting:

The CWG was of mixed opinion as to whether an infinite recursion in a constexpr function should be ill-formed or simply render an expression non-constant.

Proposed resolution (January, 2011):

Add the following bullet in 7.7 [expr.const] paragraph 2: