std: error: language dialect differs ‘C++2 6/contracts’, expected ‘C++26/contracts/re flection’

Saifi Khan <[email protected]> Sat, 11 Jul 2026 03:44:31 +0000 (UTC)
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
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=c++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=c++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 ‘C++26/contracts’, expected ‘C++26/contracts/reflection’
  std: error: failed to read compiled module: Bad file data
  std: note: compiled module file is ‘gcm.cache/std.gcm’
  std: fatal error: returning to the gate for a mechanical issue
compilation terminated.


The line that stands out is,

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


How can the language dialect differ, when i'm using the same toolchain ?

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 ?


warm regards
Saifi.