New adopted paper: N3652, Relaxing Constraints on constexpr Functions -- Richard Smith

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3652

Date: 2013-04-18

Relaxing constraints on constexpr functions

by Richard Smith

This is a major extension to constexpr. Excerpt:

This paper describes the subset of N3597 selected for inclusion in C++14, relaxing a number of restrictions on constexpr functions. These changes all received overwhelmingly strong or unopposed support under review of the Evolution Working Group. It also incorporates Option 2 of N3598.

The changes selected by the Evolution Working Group were:

  • Allow declarations within constexpr functions, other than:
       static or thread_local variables
       uninitialized variables
  • Allow if and switch statements (but not goto)
  • Allow all looping statements: for (including range-based for), while, and do-while
  • Allow mutation of objects whose lifetime began within the constant expression evaluation.

In addition, in discussion of N3598, Option 2 was selected, which removes the rule that a constexpr non-static member function is implicitly const.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.