Constexpr functions and return braced-init-list
9.2.6 [dcl.constexpr]
Mike Miller

Created on 2009-03-11.00:00:00 last changed 96 months ago


Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting as part of paper N3268.]

Date: 2010-03-15.00:00:00

Notes from the March, 2010 meeting:

The new wording added in 7.7 [expr.const] in support of reference parameters for constexpr functions should also be considered to see whether additional changes are needed.

Date: 2010-03-15.00:00:00

Proposed resolution (March, 2010):

  1. Change 8.7.4 [stmt.return] paragraph 2 as follows:

  2. A return statement without an expression with neither an expression nor a braced-init-list can be used only in functions that do not return a value...
  3. Change 9.2.6 [dcl.constexpr] paragraph 3 bullets 4 and 5 as follows:

    • its function-body shall be a compound-statement of the form

        { return expression ; }

      where expression is a potential constant expression (5.19), or

        { return braced-init-list ; }

      where every assignment-expression that is an initializer-clause appearing directly or indirectly within the braced-init-list is a potential constant expression

    • every constructor call and implicit conversion used in converting expression to the function return type initializing the return value (8.7.4 [stmt.return], 9.4 [dcl.init]) shall be one of those allowed in a constant expression (7.7 [expr.const]).

Date: 2009-03-11.00:00:00

The body of a constexpr function is required by 9.2.6 [dcl.constexpr] paragraph 3 to be of the form

    { return expression; }

However, there does not seem to be any good reason for prohibiting the alternate return syntax involving a braced-init-list. The restriction should be removed.

Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3326
2011-04-10 00:00:00adminsetstatus: drafting -> fdis
2010-03-29 00:00:00adminsetmessages: + msg2577
2010-03-29 00:00:00adminsetstatus: review -> drafting
2010-02-16 00:00:00adminsetmessages: + msg2533
2010-02-16 00:00:00adminsetstatus: drafting -> review
2009-08-03 00:00:00adminsetstatus: open -> drafting
2009-03-11 00:00:00admincreate