C++ Logo


Advanced search

[module.import] Which are these TUs exported by T?

From: jim x <xmh970252187_at_[hidden]>
Date: Mon, 20 Jun 2022 10:17:39 +0800
I have an interpretation for the recursive application of [module.import]
p7, which makes a module unit export more TUs. Consider this example

// translation unit #1
export module M:C;

// translation unit #2
export module M:B;
import :C;

// translation unit #3
export module M;
export import :B;

// translation unit #4
import M;

First, the *module-import-declaration*
<https://eel.is/c++draft/module.import#nt:module-import-declaration> in #3
imports partition module `M:B`.

According to the following rule

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.

There is a non-exported module-import-declaration in TU #2, and
the module-import-declaration in #3 that imports `M:B` is in the module
unit `#3` of module `M`, hence the module-import-declaration in #3 not only
imports `M:B` but also imports `M:C`.

[module.import] p7 also says

When a *module-import-declaration*
<https://eel.is/c++draft/module.import#nt:module-import-declaration> imports
a translation unit T, it also imports all translation units imported by
exported *module-import-declaration*
<https://eel.is/c++draft/module.import#nt:module-import-declaration>*s* in T;
such translation units are said to be *exported*
<https://eel.is/c++draft/module.import#def:module,exported> by T.

The exported *module-import-declaration*
<https://eel.is/c++draft/module.import#nt:module-import-declaration> at
`#3` imports `M:B` and `M:C` as aforementioned, so `M:B` and `M:C` are
exported by `#3`?

GCC does not accept this interpretation, which only considers that `M:B` is
exported by `#3`. Which are these TUs referred to by "such translation units"
in "such translation units are said to be *exported*
<https://eel.is/c++draft/module.import#def:module,exported> by T.
<https://eel.is/c++draft/module.import#7.sentence-1>"? According to the
context, "such translations units" should refer to all TUs that are
imported by the *module-import-declaration*
<https://eel.is/c++draft/module.import#nt:module-import-declaration>. Why
does GCC only consider `M:B` as being exported?

Received on 2022-06-20 02:17:51