Yes, but the source of confusion is that the specification of importing a named module is as if you take the exported module-import-declarations in the nominated modules and then execute those in the importing translation units, and those don’t get subject to the fundamental constraint that you quote.



Exactly why we need to clarify the normative text to say explicitly that importing a named module does not bring in any macro even if the nominated module re-exported a header unit which might bring in macros if imported directly.  Even if we believe there is a (long) chain of inference to arrive there, it is better to have an explicit normative text to that effect.


-- Gaby


From: Daniela Engert <dani@ngrt.de>
Sent: Friday, December 16, 2022 10:07 AM
To: core@lists.isocpp.org
Cc: Gabriel Dos Reis <gdr@microsoft.com>; sg15@lists.isocpp.org
Subject: Re: [isocpp-core] Named modules, macros, and re-exporting header units


Am 16.12.2022 um 18:58 schrieb Gabriel Dos Reis via Core:



In the SG15 telecon this morning, the issue of whether a named modules can bring in macros via re-exported header units was discussed.

The issue is that the current specification of module-import-declaration: 10.3/7


When a module-import-declaration imports a translation unit T, it also imports all translation units imported by exported module-import-declarations in T; such translation units are said to be exported by T. Additionally, when a module-import-declaration in a module unit of some module M imports another module unit U of M, it also imports all translation units imported by non-exported module-import-declarations in the module unit purview of U.91 These rules can in turn lead to the importation of yet more translation units.


places no restrictions on “it also imports all translation units imported by exported module-import-declarations in T;”.

It was pointed out that there is a CWG issue


    [cpp.import] Example should demonstrate that module imports do not import macros · Issue #199 · cplusplus/CWG · GitHub


to add an example that importing named modules don’t bring in any macros at all.  That is a fundamental invariant for anything to work.  In addition to adding the example, I believe we need to clarify the wording.  The fact that the text is confusing on this aspect is a defect, from my perspective.

We need to take into account [module.import]/5 that states that imports *not* nominating header units do *not* affect the preprocessor state. Current implementations disagree: https://twitter.com/DanielaKEngert/status/1603421930337484803






-- Gaby

Core mailing list
Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/core
Link to this post: http://lists.isocpp.org/core/2022/12/13656.php


PGP/GPG: 2CCB 3ECB 0954 5CD3 B0DB 6AA0 BA03 56A1 2C4638C5