C++ Logo

std-proposals

Advanced search

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

From: Rainer Deyke <rainerd_at_[hidden]>
Date: Sat, 9 May 2026 09:38:15 +0200
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]

Received on 2026-05-09 07:38:26