Title
Unclear status of translation unit with module keyword
Status
tentatively ready
Section
15.1 [cpp.pre]
Submitter
Chuanqi Xu

Created on 2024-08-15.00:00:00 last changed 6 days ago

Messages

Date: 2024-09-27.20:34:22

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]
Date: 2024-09-27.20:34:22

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.

Date: 2024-09-25.17:32:08

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

History
Date User Action Args
2024-09-27 20:34:22adminsetmessages: + msg7824
2024-09-27 20:34:22adminsetstatus: review -> tentatively ready
2024-09-25 17:32:08adminsetmessages: + msg7822
2024-09-25 17:32:08adminsetstatus: open -> review
2024-08-15 00:00:00admincreate