#1081132 g++-14: Modules compiled with --std=c++23 can't be used with --std=c++26 and v.v.

Package:
g++-14
Source:
g++-14
Description:
GNU C++ compiler
Submitter:
Frank B. Brokken
Date:
2024-09-08 12:03:01 UTC
Severity:
normal
#1081132#5
Date:
2024-09-08 10:45:03 UTC
From:
To:
Dear Maintainer,

   * What led up to the situation?

When trying to import a module in a C++ source file when --std=c++23 was
specified when the module was compiled and --std=c++26 is specified when the
source file is compiled the compiler shows the following error message:

    Module: error: language dialect differs ‘C++23/coroutines’, expected ‘C++26/coroutines’
    Module: error: failed to read compiled module: Bad file data
    Module: note: compiled module file is ‘gcm.cache/Module.gcm’
    Module: fatal error: returning to the gate for a mechanical issue
    compilation terminated.

When --std=c++26 was specified when the module was compiled the compiler does
not show an error message.

   * What exactly did you do (or not do) that was effective (or
     ineffective)?

The following source file (e.g., interface.cc) defines the module:

    module Module;
    export int value;

and the module is used in the following source file (e.g., fun.cc):

    import Module;

    void fun()
    {
        value = 10;
    }

'interface.cc' was compiled using using
    g++ --std=c++23 -fmodules-ts -c interface.cc
'fun.cc' was compiled using using
    g++ --std=c++26 -fmodules-ts -c fun.cc

   * What was the outcome of this action?

when compiling 'interface.cc' and 'fun.cc' using the mentioned g++ commands
the abovementioned error is reported. When using c++26 when compiling
interface.cc and c++23 when compiling fun.cc a comparable error is
reported. When specifying the same standard (either c++23 or c++26 when
compiling both files no error is reported.

   * What outcome did you expect instead?

Normally specifying a more recent C++ standard then files compiled with an
older standard can still be used. I would have expected the same situation
when compiling/using modules. Maybe it's just the switch from c++23 to c++26,
and will the error disappear when combining c++26 and the standard following
c++26, but if not, then we may have to recompile all already compiled modules
or all source files using modules once a new standard becomes available, which
is -let's say- inconvenient.

#1081132#10
Date:
2024-09-08 11:52:17 UTC
From:
To:
Dear Frank B. Brokken, you wrote:

This must be:

      export module Module;
      export int value;