https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99072

            Bug ID: 99072
           Summary: [modules] Compiling header unit with partial
                    preprocessing (-E -fdirectives-only) twice causes CRC
                    mismatch
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: boris at kolpackov dot net
  Target Milestone: ---

With partial preprocessing (-E -fdirectives-only) compiling the same header
with the same options twice results in two CRC-incompatible .gcm files:

cat <<EOF >string.hxx 
#include <string>
EOF

cat <<EOF >hello.mxx
export module hello;

import "string.hxx";

export std::string format_hello (const char* n)
{
  return "Hello, " + std::string (n) + '!';
}
EOF

cat <<EOF >main.cxx
#include <cassert>

import "string.hxx";
import hello;

int main ()
{
  assert (format_hello ("World") == "Hello, World!");
}
EOF

cat <<EOF >hello.txt
./string.hxx string.so.gcm
hello hello.so.gcm
EOF

cat <<EOF >main.txt
./string.hxx string.gcm
hello hello.so.gcm
EOF

g++ -std=c++2a -fmodules-ts -fmodule-mapper=hello.txt -E -fdirectives-only
-fmodule-header -x c++-header -o string.so.ii string.hxx
g++ -std=c++2a -fmodules-ts -fmodule-mapper=hello.txt -fpreprocessed
-fdirectives-only -fmodule-header -x c++-header string.so.ii

g++ -std=c++2a -fmodules-ts -fmodule-mapper=hello.txt -x c++ -c hello.mxx

g++ -std=c++2a -fmodules-ts -fmodule-mapper=main.txt -E -fdirectives-only
-fmodule-header -x c++-header -o string.ii string.hxx
g++ -std=c++2a -fmodules-ts -fmodule-mapper=main.txt -fpreprocessed
-fdirectives-only -fmodule-header -x c++-header string.ii

g++ -std=c++2a -fmodules-ts -fmodule-mapper=main.txt -x c++ -c main.cxx
In module imported at main.cxx:5:1:
hello: error: import ‘./string.hxx’ has CRC mismatch

The really strange thing is that the .ii files are identical:

diff string.ii string.so.ii && echo same
same

Also, there is no error if to compile string.hxx without -E -fdirectives-only:

g++ -std=c++2a -fmodules-ts -fmodule-mapper=hello.txt -fmodule-header -x
c++-header string.hxx

g++ -std=c++2a -fmodules-ts -fmodule-mapper=main.txt -fmodule-header -x
c++-header string.hxx

Reply via email to