Title
odr-use of reference variables
Status
cd3
Section
6.3 [basic.def.odr]
Submitter
Richard Smith

Created on 2012-03-01.00:00:00 last changed 130 months ago

Messages

Date: 2013-04-15.00:00:00

[Moved to DR at the April, 2013 meeting.]

Date: 2012-10-15.00:00:00

Proposed resolution (October, 2012):

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 is an object that satisfies the requirements for appearing in a constant expression (7.7 [expr.const]) 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

We have a special case in 6.3 [basic.def.odr] paragraph 2 that variables which satisfy the requirements for appearing in a constant expression are not odr-used if the lvalue-to-rvalue conversion is immediately applied. This special case only applies to objects, and thus does not apply to variables of reference type. This inconsistency seems strange, and there is implementation divergence:

  int n;
  void f() {
   constexpr int &r = n;
   [] { return r; }; // error: r is odr-used but not captured
  }

This code is accepted by g++ but rejected by clang. Should r be odr-used here?

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-05-03 00:00:00adminsetmessages: + msg4367
2013-05-03 00:00:00adminsetstatus: ready -> dr
2012-11-03 00:00:00adminsetmessages: + msg4042
2012-11-03 00:00:00adminsetstatus: open -> ready
2012-03-01 00:00:00admincreate