[Bug c++/124735] New: Unexpected -Wtemplate-body in C++ modules program (conflicting deduced return type for imported declaration)
sebj_coder3 at pm dot me
gcc-bugzilla@gcc.gnu.org
Tue Mar 31 14:34:19 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124735
Bug ID: 124735
Summary: Unexpected -Wtemplate-body in C++ modules program
(conflicting deduced return type for imported
declaration)
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sebj_coder3 at pm dot me
Target Milestone: ---
I'm getting an unexpected -Wtemplate-body compiling a C++20 modules program.
It can't be worked around by passing -Wno-template-body (the compile still
fails).
Could be related to this bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120644
I apologise for not having a minimal version of the code to trigger this bug.
Steps to reproduce:
# Dependencies are OpenGL, Freetype and GLFW (only for the top level
CMakeLists,
# the bug-generating code won't use these). Run your distro's equivalent of the
# Debian-like:
sudo apt install ninja-build \
librapidxml-dev freeglut3-dev libglu1-mesa-dev libxmu-dev \
libxi-dev libglfw3-dev libfreetype-dev
# Clone mathplot
git clone git@github.com:sebsjames/mathplot
cd mathplot
# Check out the modules_cpp20 branch and init/update two submodules
git checkout dev/modules # Commit 49f1686, dated 2026/03/31
git submodule init
git submodule update
mkdir build
cd build
# Configure.
CC=/path/to/gcc CXX=/path/to/g++ cmake .. -GNinja
# Build the 'hexgrid' program that triggers the -Wtemplate-body:
ninja hexgrid
Output:
15:28:45 bgcc] ninja hexgrid
[3/5] Building CXX object
examples/CMakeFiles/hexgrid.dir/__/mplot/HexGridVisual.cppm.o
FAILED: examples/CMakeFiles/hexgrid.dir/__/mplot/HexGridVisual.cppm.o
examples/CMakeFiles/hexgrid.dir/mplot.hexgridvisual.gcm
/opt/gcc-master/bin/g++ -I/home/seb/src/mathplot -I/usr/include/hdf5/serial
-I/home/seb/src/mathplot/maths -I/home/seb/src/mathplot/json/include
-I/home/seb/src/mathplot/include/rapidxml-1.13 -isystem /usr/include/freetype2
-g -Wall -Wextra -Wpedantic -pedantic-errors -Werror -Wfatal-errors -Wno-psabi
-O3 -fconstexpr-ops-limit=5000000000 -DMPLOT_HAVE_STD_FORMAT -fopenmp
-DMPLOT_FONTS_DIR="\"/home/seb/src/mathplot/fonts\"" -freport-bug -std=gnu++20
-MD -MT examples/CMakeFiles/hexgrid.dir/__/mplot/HexGridVisual.cppm.o -MF
examples/CMakeFiles/hexgrid.dir/__/mplot/HexGridVisual.cppm.o.d -fmodules-ts
-fmodule-mapper=examples/CMakeFiles/hexgrid.dir/__/mplot/HexGridVisual.cppm.o.modmap
-MD -fdeps-format=p1689r5 -x c++ -o
examples/CMakeFiles/hexgrid.dir/__/mplot/HexGridVisual.cppm.o -c
/home/seb/src/mathplot/mplot/HexGridVisual.cppm
In file included from /opt/gcc-master/include/c++/16.0.1/set:64,
from /home/seb/src/mathplot/maths/sm/hexgrid.cppm:16,
of module sm.hexgrid, imported at
/home/seb/src/mathplot/mplot/HexGridVisual.cppm:14:
/opt/gcc-master/include/c++/16.0.1/bits/stl_tree.h:2299:7: error: conflicting
deduced return type for imported declaration ‘auto std::operator<=>(const
_Rb_tree<unsigned int, unsigned int, _Identity<unsigned int>, less<unsigned
int>, allocator<unsigned int> >&, const _Rb_tree<unsigned int, unsigned int,
_Identity<unsigned int>, less<unsigned int>, allocator<unsigned int> >&)’
[-Wtemplate-body]
2299 | operator<=>(const _Rb_tree& __x, const _Rb_tree& __y)
| ^~~~~~~~
compilation terminated due to -Wfatal-errors.
ninja: build stopped: subcommand failed.
More information about the Gcc-bugs
mailing list