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

2024-11-11


2927. Unclear status of translation unit with module keyword

Section: 15.1  [cpp.pre]     Status: tentatively ready     Submitter: Chuanqi Xu     Date: 2024-08-15

Consider:

  using module = int;
  module i;
  int foo() {
    return i;
  }

Is this a valid translation unit?

It is not a valid module-file, because the translation unit does not start with module or export module (15.4 [cpp.module]). It is also not a valid traditional preprocessing-file (15.1 [cpp.pre]), because module i is considered a preprocessing directive (15.1 [cpp.pre] bullet 1.3, which is never a text-line (15.1 [cpp.pre] paragraph 2):

A sequence of preprocessing tokens is only a text-line if it does not begin with a directive-introducing token. ...

A clarifying note would be appreciated.

Possible resolution (August, 2024):

Change in 15.1 [cpp.pre] paragraph 2 as follows:

A sequence of preprocessing tokens is only a text-line if it does not begin with a directive-introducing token. [ Note: A source line starting with module identifier is always interpreted as a preprocessing directive, not as a text-line, even if parsing the source file as a preprocessing-file subsequently fails. -- end note ]

A sequence of preprocessing tokens is only a conditionally-supported-directive if ...

CWG 2024-09-13

A source line starting with module identifier appearing in a macro argument may or may not be interpreted as a preprocessing directive (15.6.2 [cpp.subst] paragraph 13), thus the note as written is incorrect.

Proposed resolution (approved by CWG 2024-09-27):

Change in 15.1 [cpp.pre] paragraph 2 as follows:

A sequence of preprocessing tokens is only a text-line if it does not begin with a directive-introducing token. [ Example:

  using module = int;
  module i;       // not a text-line and not a control-line
  int foo() {
    return i;
  }
The example is not a valid preprocessing-file. -- end example]