[Bug c++/126869] New: Loss of character due to adding header

d7d1cd at mail dot ru via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126869

            Bug ID: 126869
           Summary: Loss of character due to adding header
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: d7d1cd at mail dot ru
  Target Milestone: ---

I encountered the following problem when using module partitions. I have this
header:
    $ cat foo.h
    #pragma once
    class Foo {};


It's added to the M module partition:
    $ cat foo.ixx
    module;
    #include "foo.h"
    export module M : foo;
    export using ::Foo;


The module interface looks like this:
    $ cat module.ixx
    module;
    #include "foo.h"
    export module M;
    export import : foo;


The module is used as follows:
    $ cat main.cc
    import M;
    int main() {
        Foo f;
    }


When compiling these files, I get the following error:
    $ g++ -std=c++23 -fmodules foo.ixx module.ixx main.cc 
    main.cc: In function ‘int main()’:
    main.cc:3:5: error: ‘Foo’ was not declared in this scope
        3 |     Foo f;
          |     ^~~


If I remove the header inclusion from the interface, the compilation succeeds.
Here's an example in the online compiler: https://godbolt.org/z/Mo6oKW7vh
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.