Title
Modules, exposures: odr-use determination too simple
Status
open
Section
6.7 [basic.link]
Submitter
Hubert Tong

Created on 2025-12-18.00:00:00 last changed 1 week ago

Messages

Date: 2026-01-08.17:03:18

Suggested resolution:

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

A variable is named by an expression if the expression is an id-expression or splice-expression (7.5.9 [expr.prim.splice]) that designates it. A variable x that is named by a potentially-evaluated expression N that appears at a point P is odr-used by N unless
  • x is a reference that is usable in constant expressions at P (7.7 [expr.const]), or ...
  • ...
Date: 2025-12-18.00:00:00

Consider:

  export module M;

  static int x;             // OK, TU-local
  static int &rx = x;       // OK, TU-local

  export inline int &f() {
    return rx;              // OK(!), not an odr-use
  }

The declaration of f is not an exposure because the reference to rx is not an odr-use (6.7 [basic.link] bullet 14.4), but it is impossible with current implementation technology to simulate naming x in importing translation units.

For a related example:

  export module M;

  static int x;               // OK, TU-local
  extern "C++" int &rx = x;   // OK, not an exposure (not constexpr)

  export inline int &f() {
    return rx;                // OK(!), not an odr-use
  }

In importing translation units, rx is not usable in constant expressions.

Finally:

  export module M;

  extern "C++" int x = 0;
  static int &rx = x;

  export constexpr inline int &f() {
    return rx;                // OK, not an odr-use
  }
History
Date User Action Args
2026-01-08 17:03:18adminsetmessages: + msg8451
2025-12-18 00:00:00admincreate