https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128318
Bug ID: 128318
Summary: ICE: Segmentation fault in transfer_defining_module
with -fmodules-ts when an extern const variable is
redeclared inline constexpr
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ambroise.leclerc at gmail dot com
Target Milestone: ---
With -fmodules-ts, redeclaring a non-inline extern const variable as inline
constexpr makes cc1plus crash. The translation unit does not use modules. The
code is valid: the first declaration is not a definition, and the definition is
the first inline declaration.
Reproducer (t.cpp)
extern const int t;
inline constexpr int t = 0;
> g++ -std=gnu++23 -fmodules-ts -c t.cpp
Output (GCC 16.1.0)
t.cpp:2:22: internal compiler error: Segmentation fault
2 | inline constexpr int t = 0;
transfer_defining_module(tree_node*, tree_node*) gcc/cp/module.cc:22326
duplicate_decls(tree_node*, tree_node*, bool, bool) gcc/cp/decl.cc:2717
pushdecl(tree_node*, bool) gcc/cp/name-lookup.cc:4090
start_decl(...) gcc/cp/decl.cc:6794
Versions
GCC 13.4.0 and 15.2.0 accept the code. GCC 16.1.0 and 16.2.0 crash at the same
place. Same result with -std=c++20, -std=gnu++23, -std=gnu++26. No ICE without
-fmodules-ts, nor with plain constexpr (no inline).
Impact
CMake 4.2 or later with Ninja adds -fmodules-ts to every C++20+ target
(CMP0155). NVIDIA stdexec declares forwarding_query this way in
stdexec/__detail/__query.hpp (extern forwarding_query_t const forwarding_query;
then inline constexpr forwarding_query_t forwarding_query{};), so every
translation unit that includes <stdexec/execution.hpp> crashes.