Title
odr-use of class object in lvalue-to-rvalue conversion
Status
c++14
Section
6.3 [basic.def.odr]
Submitter
Richard Smith

Created on 2013-08-21.00:00:00 last changed 121 months ago

Messages

Date: 2014-02-15.00:00:00

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

Date: 2013-09-15.00:00:00

Proposed resolution (September, 2013):

Change 6.3 [basic.def.odr] paragraph 3 as follows:

A variable x whose name appears as a potentially-evaluated expression ex is odr-used unless x satisfies the requirements for appearing in a constant expression (7.7 [expr.const]) applying the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) to x yields a constant expression (7.7 [expr.const]) that does not invoke any non-trivial functions and, if x is an object, ex is an element of the set of potential results of an expression e, where either the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is applied to e, or e is a discarded-value expression ( Clause 7 [expr]). this is odr-used...
Date: 2022-09-25.18:08:42
N3690 comment CA 28

According to 7.3.2 [conv.lval] paragraph 2,

if the glvalue has a class type, the [lvalue-to-rvalue] conversion copy-initializes a temporary of type T from the glvalue and the result of the conversion is a prvalue for the temporary.

The implications of such a conversion for odr-use do not appear to have been factored into 6.3 [basic.def.odr] paragraph 3, which exempts constant objects that are immediately lvalue-to-rvalue converted. For example, given

  struct S { int n; };
  struct T {
    static constexpr S s = {};
  };
  void f(...);
  void g() { f(T::s); }

Does this odr-use T::s, requiring it to have a definition, because of binding it to the reference parameter of S's copy constructor? How about

  struct S { int n; };
  void f(...);
  void g() {
    constexpr S s = {};
    [] { f(s); };
  }

Does s need to be captured? There is implementation variance on both these examples.

History
Date User Action Args
2014-11-24 00:00:00adminsetstatus: dr -> c++14
2014-03-03 00:00:00adminsetmessages: + msg4927
2014-03-03 00:00:00adminsetstatus: ready -> dr
2013-10-14 00:00:00adminsetmessages: + msg4566
2013-10-14 00:00:00adminsetstatus: open -> ready
2013-08-21 00:00:00admincreate