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

2024-12-19


2957. Evaluating a reference member should constitute access

Section: 7.6.1.5  [expr.ref]     Status: open     Submitter: Jiang An     Date: 2024-11-06

(From submissions #634 and #637.)

The standard permits that references do not occupy storage. The term "access" (3.1 [defns.access]) is not applicable to references. Yet, references can participate in data races (6.9.1 [intro.execution] paragraph 10, 6.9.2.2 [intro.races] paragraph 2). For example:

  int x, y;
  struct S {
    int &r;
  } s{x};

  void thread_1() {
    new (&s) S{y};   // transparent replacement
  }

  void thread_2() {
    auto& r = s.r; // OK ?! Refers to x or y?
  }

Also consider the impact on constant evaluation:

  int n{};
  struct S { int& r; };
  constexpr S s{n};
  constexpr volatile S s2{n};

  static_assert(&static_cast<const volatile S&>(s).r == &n); // GCC rejects
  static_assert(&s2.r == &n); // GCC and Clang reject