https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125230
--- Comment #5 from Rainer Deyke <rainerd at eldwood dot com> --- (In reply to Drea Pinski from comment #3) > https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Modules.html I don't see any text in the link that suggests that #includes in general are translated into imports. The closest I see is this statement: But for the standard library in particular this is unnecessary: if a header unit has been built for the libstdc++ ‘bits/stdc++.h’ header, the compiler will translate an ‘#include’ of any importable standard library header into an import of that header unit, speeding up compilation without needing to specify ‘-include’. Note that the ‘bits/stdc++.h’ header unit is also built by the --compile-std-module option. But that statement is specifically about the standard library, and does not suggest that the same translation happens to other #includes. > But this is exactly how c++20 modules are supposed to work. Checking on https://cppreference.com/cpp/preprocessor/include, I see that this behavior is in fact standard-compliant, but not mandated. The exact text is this: If the header identified by the header-name (i.e., < h-char-sequence > or " q-char-sequence ") denotes an importable header, it is implementation-defined whether the #include preprocessing directive is instead replaced by an import directive of the form import header-name ; new-line This is problematic because "importable header" is never defined. It can reasonably mean "any header" in a compiler that compiles header units on demand, in which case my header-only library cannot work at all. I believe this is a defect in the standard. Anyway, given that this is standard-conformant behaviors, it's also not difficult to work around. a-indirect.hpp: #include "a.hpp" b.cpp: #define A_IMPL #include "a.hpp" c.cpp: import "a-indirect.hpp" c.cpp:
