C++ Logo

std-proposals

Advanced search

Re: [std-proposals] #includes turning into imports breaks existing usage

From: Andre Kostur <andre_at_[hidden]>
Date: Sat, 9 May 2026 06:15:48 -0700
Thank-you for the gcc bugzilla link, that was helpful.

I'm still mulling over what I think about it, as I'm holding 2 thoughts:

1) In a way, you asked for it. By compiling a .hpp as a header
module, you're effectively declaring to the compiler that a.hpp is an
importable header. Thus later on when you #included it again, the
compiler notes that a.hpp is an importable header. Essentially gcc
has implementation-defined that any header that has been compiled as a
header unit is an importable header. Not a completely unreasonable
thing to conclude. If it's not importable, then why would one compile
it as if it was? (Note that it does not appear to be "any header",
just headers which the user is already treating as if they are
importable headers)

Leading to:

2) I'm not convinced that I like this implementation-defined
behaviour. It's my header, I said "#include", thus by gosh:
"#include" it, don't "import" it. Rewriting the Standard ones is
acceptable as there should be no way for me to reasonably figure out
that it has happened. That's not true for user-supplied headers. I
suppose it does provide a somewhat smoother path to using modules:
compile the header as a header unit, and everywhere else behaves as if
it was imported automatically. Still not sure I like that either.


On Sat, May 9, 2026 at 12:38 AM Rainer Deyke via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
>
>
> On 5/8/26 21:29, Andre Kostur wrote:
> > On Fri, May 8, 2026 at 12:02 PM Rainer Deyke via Std-Proposals
> > <std-proposals_at_[hidden]> wrote:
> >>
> >> You might claim it's my own fault for precompiling headers that are not,
> >> in fact, importable. To which my reply is fourfold:
> >
> > You appear to have a specific example that you feel is misbehaving.
> > Perhaps if you provided that example we'd have something more concrete
> > to work with.
>
> The following minimal example fails because the #include was transformed
> into an import (as seen in the generated b.ii file). I reported this to
> gcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125230) and was told
> that "this is exactly how c++20 modules are supposed to work".
>
> a.hpp:
> void f();
>
> #ifdef A_IMPL
> void f() {
> }
> #endif
>
> b.cpp:
> #define A_IMPL
> #include "a.hpp"
>
> int main() {
> f();
> }
>
> test.sh:
> ~/toolchains/gcc/16.1.0/bin/g++ -save-temps -Wall -Wextra -fmodules
> -x c++-header a.hpp
> ~/toolchains/gcc/16.1.0/bin/g++ -save-temps -Wall -Wextra -fmodules
> -c b.cpp
> ~/toolchains/gcc/16.1.0/bin/g++ -save-temps -Wall -Wextra b.o
>
>
> --
> Rainer Deyke - rainerd_at_[hidden]
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-05-09 13:16:06