Title
Named module imports do not import macros
Status
ready
Section
15.5 [cpp.import]
Submitter
Richard Smith

Created on 2022-12-09.00:00:00 last changed 3 weeks ago

Messages

Date: 2023-01-07.14:27:01

Proposed resolution (approved by CWG 2023-01-06):

  1. Change in 10.3 [module.import] paragraph 7 as follows:

    ... These rules can in turn lead to the importation of yet more translation units. [ Note: Such indirect importation does not make macros available, because a translation unit is a sequence of tokens in translation phase 7 (5.2 [lex.phases]). Macros can be made available by directly importing header units as described in 15.5 [cpp.import]. -- end note ]
  2. Add to the example in 15.5 [cpp.import] paragraph 8 as follows:

      import "a.h";  // point of definition of #1, #2, and #3, point of undefinition of #1 in "e.h"
      import "d.h";  // point of definition of #4 and #5 in "e.h"
      int a = Y;     // OK, active macro definitions #2 and #4 are valid redefinitions
      int c = Z;     // error: active macro definitions #3 and #5 are not valid redefinitions of Z
    
    Module unit f:
    export module f;
    export import "a.h";
    
    int a = Y;    // OK
    
    Translation unit #1:
    import f;
    int x = Y;   // error: Y is neither a defined macro nor a declared name
    
    -- end example ]
Date: 2023-01-07.14:27:01

It should be clarified via an example or a note that named module imports do not make macros available.

History
Date User Action Args
2023-01-07 14:27:01adminsetmessages: + msg7120
2023-01-07 14:27:01adminsetstatus: open -> ready
2022-12-17 19:35:19adminsetmessages: - msg7096
2022-12-16 23:08:46adminsetstatus: review -> open
2022-12-09 22:41:41adminsetstatus: open -> review
2022-12-09 22:40:08adminsetmessages: + msg7096
2022-12-09 00:00:00admincreate