Title
Const integral subobjects
Status
cd4
Section
7.7 [expr.const]
Submitter
Richard Smith

Created on 2013-09-20.00:00:00 last changed 94 months ago

Messages

Date: 2014-11-15.00:00:00

[Moved to DR at the November, 2014 meeting.]

Date: 2014-02-15.00:00:00

Proposed resolution (February, 2014):

Change 7.7 [expr.const] bullet 2.7 as follows:

A conditional-expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine (6.9.1 [intro.execution]), would evaluate one of the following expressions:

  • ...

  • an lvalue-to-rvalue conversion (7.3.2 [conv.lval]) unless it is applied to

    • a non-volatile glvalue of integral or enumeration type that refers to a complete non-volatile const object with a preceding initialization, initialized with a constant expression [Note: a string literal (5.13.5 [lex.string]) corresponds to an array of such objects. —end note], or

    • a non-volatile glvalue that refers to a subobject of a string literal (5.13.5 [lex.string]), or

    • a non-volatile glvalue that refers to a non-volatile object defined with constexpr...

Date: 2013-09-20.00:00:00

The requirements for a constant expression in 7.7 [expr.const] permit an lvalue-to-rvalue conversion on

a non-volatile glvalue of integral or enumeration type that refers to a non-volatile const object with a preceding initialization, initialized with a constant expression

This does not exclude subobjects of objects that are not compile-time constants, for example:

  int f();
  struct S {
    S() : a(f()), b(5) {}
    int a, b;
  };
  const S s;
  constexpr int k = s.b;

This rule is intended to provide backward compatibility with pre-constexpr C++, but it should be restricted to complete objects. Care should be taken in resolving this issue not to break the handling of string literals, since use of their elements in constant expressions depends on the current form of this rule.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: + msg5353
2014-11-24 00:00:00adminsetstatus: ready -> dr
2014-03-03 00:00:00adminsetmessages: + msg4816
2014-03-03 00:00:00adminsetstatus: open -> ready
2013-09-20 00:00:00admincreate