This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 113d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-03-20


1472. odr-use of reference variables

Section: 6.3  [basic.def.odr]     Status: CD3     Submitter: Richard Smith     Date: 2012-03-01

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

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?

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...