https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124430
Bug ID: 124430
Summary: Unexpected error including module-containing header
before nlohmann/json.hpp
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 am converting my maths and mathplot libraries over to C++ 20 modules and this
is one of the problems that I encountered using g++ to compile.
I made a module (test1.cppm) that includes a couple of headers.
The first header (has_tools.h) itself contains a module import (of tools.cppm).
The second header is a development branch of the well known json library
nlohmann/json. The branch 'develop' is supposed to be modules-friendly.
g++ does not want to compile this module with the headers in this order.
clang++ appears to be happy with it (clang version 18 and up, I think).
I've made a minimal project that demonstrates the error that occurred in a
larger codebase:
https://github.com/sebsjames/gcc15_modules_test
The build command (in build_g++.sh) are:
/opt/gcc-15/bin/g++ -std=c++20 -fmodules -c tools.cppm -I. -Ijson/include
-Wfatal-errors
/opt/gcc-15/bin/g++ -std=c++20 -fmodules -c test1.cppm -I. -Ijson/include
-Wfatal-errors
The error output is:
[11:46:26 gcc15_modules_test] ./build_g++.sh
In file included from /opt/gcc-15/include/c++/15.2.1/algorithm:63,
from json/include/nlohmann/json.hpp:21,
from test1.cppm:4:
/opt/gcc-15/include/c++/15.2.1/bits/stl_algo.h:5633:5: error: redefinition of
‘template<class _ForwardIterator, class _Compare> constexpr _ForwardIterator
std::__min_element(_ForwardIterator, _ForwardIterator, _Compare)’
5633 | __min_element(_ForwardIterator __first, _ForwardIterator __last,
| ^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
[11:46:29 gcc15_modules_test]
I've tested this with a from-git compiled version of g++ (gcc-16 prerelease)
and I get the same error.
Expected behaviour: both modules compile.