Title
Constant expressions in constexpr initializers
Status
cd1
Section
9.2.6 [dcl.constexpr]
Submitter
Mike Miller

Created on 2007-08-12.00:00:00 last changed 161 months ago

Messages

Date: 2008-09-15.00:00:00

[Voted into the WP at the September, 2008 meeting.]

Date: 2008-06-15.00:00:00

Proposed resolution (June, 2008):

Change 9.2.6 [dcl.constexpr] paragraph 7 as follows:

A constexpr specifier used in an object declaration declares the object as const. Such an object shall be initialized, and every expression that appears in its initializer (8.5) initialized. If it is initialized by a constructor call, the constructor shall be a constexpr constructor and every argument to the constructor shall be a constant expression. Otherwise, every full-expression that appears in its initializer shall be a constant expression. Every implicit conversion used...
Date: 2007-08-12.00:00:00

The current wording of 9.2.6 [dcl.constexpr] paragraph 7 seems not quite correct. It reads,

A constexpr specifier used in an object declaration declares the object as const. Such an object shall be initialized, and every expression that appears in its initializer (9.4 [dcl.init]) shall be a constant expression.

The phrase “every expression” is intended to cover multiple arguments to a constexpr constructor and multiple expressions in an aggregate initializer. However, it could be read (incorrectly) as saying that non-constant expressions cannot appear as subexpressions in such initializers, even in places where they do not render the full-expression non-constant (i.e., as unevaluated operands and in the unselected branches of &&, ||, and ?:). Perhaps this problem could be remedied by replacing “every expression” with “every full-expression?”

History
Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1818
2008-10-05 00:00:00adminsetstatus: ready -> cd1
2008-06-29 00:00:00adminsetmessages: + msg1680
2008-06-29 00:00:00adminsetstatus: drafting -> ready
2007-10-09 00:00:00adminsetstatus: open -> drafting
2007-08-12 00:00:00admincreate