Re: std: error: language dialect differs ‘C++26/co ntracts’, expected ‘C++26/contracts/reflection’

Jonathan Wakely via Gcc-help <[email protected]> Sat, 11 Jul 2026 07:48:21 +0100
Newsgroups gmane.comp.gcc.help
Message-ID <CAH6eHdTQNF9hoOzz-AQnUodGbPZk3Yzvwzp6wN6gvH+HoTYhkw@mail.gmail.com>
On Sat, 11 Jul 2026, 04:47 Saifi Khan, <[email protected]>
wrote:

> Hi:
>
>
> The tool environment is
>   GNU/Linux   6.12.10
>   GNU libc    2.43
>   GCC version 17.0.0 20260710 (experimental)
>
>
> The command that i use to build a 'std' module is
>
> g++ -std=3Dc++26 -g3 -fmodules -fmodule-only -fsearch-include-path -c
> bits/std.cc
>
> Now, using the same toolchain, i compile some code that uses C++26
> reflection features.
>
> g++ -std=3Dc++26 -g3 -fmodules -freflection aggregate.cc
>
>
> The error seen is thus,
>
>   /opt/gcc/include/libiberty
>   /opt/gcc/lib/gcc/x86_64-pc-linux-gnu/17.0.0/plugin/include
>   .
>
> /opt/gcc/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.=
0
>
> /opt/gcc/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.=
0/x86_64-pc-linux-gnu
>
> /opt/gcc/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.=
0/backward
>   /opt/gcc/lib/gcc/x86_64-pc-linux-gnu/17.0.0/include
>   /usr/local/include
>   /opt/gcc/include
>   /opt/gcc/lib/gcc/x86_64-pc-linux-gnu/17.0.0/include-fixed
>   /usr/include
> End of search list.
> Compiler executable checksum: 22271c86981c82a489059277b30cac3b
>
> In module imported at aggregate.cc:2:1:
>   std: error: language dialect differs =E2=80=98C++26/contracts=E2=80=99,=
 expected
> =E2=80=98C++26/contracts/reflection=E2=80=99
>   std: error: failed to read compiled module: Bad file data
>   std: note: compiled module file is =E2=80=98gcm.cache/std.gcm=E2=80=99
>   std: fatal error: returning to the gate for a mechanical issue
> compilation terminated.
>
>
> The line that stands out is,
>
> std: error: language dialect differs =E2=80=98C++26/contracts=E2=80=99, e=
xpected
> =E2=80=98C++26/contracts/reflection=E2=80=99
>
>
> How can the language dialect differ, when i'm using the same toolchain ?
>

Because you're using different options.



> I also observed that if '-freflection' is passed to the command for
> compiling bits/std.cc the error goes away.
>
> Is there some doc or code fragment, where one can read in depth about
> '-freflection' and where it needs to be passed beyond the immediate code
> that i'm working on ?
>


You must use the same options to compile a module and when importing that
module.



>
>
>