https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122514
Bug ID: 122514
Summary: [modules] ICE when instantiation references an extern
local
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nshead at gcc dot gnu.org
Blocks: 103524
Target Milestone: ---
Consider:
// test.hpp
template <auto&> struct S {};
inline void foo() {
extern int val;
void bar();
S<val> x;
S<bar> y;
}
$ g++ -fmodule-header test.hpp
test.hpp: internal compiler error: in decl_node, at cp/module.cc:9195
0x3e74d00 internal_error(char const*, ...)
../../gcc/gcc/diagnostic-global-context.cc:787
0x3e84a2e fancy_abort(char const*, int, char const*)
../../gcc/gcc/diagnostics/context.cc:1806
0x11dde16 decl_node
../../gcc/gcc/cp/module.cc:9089
0x11e3842 tree_node
../../gcc/gcc/cp/module.cc:10201
<snip>
Commenting out 'x' we get a similar error but a different line number:
test.hpp: internal compiler error: in decl_node, at cp/module.cc:9089
0x3e74d00 internal_error(char const*, ...)
../../gcc/gcc/diagnostic-global-context.cc:787
0x3e84a2e fancy_abort(char const*, int, char const*)
../../gcc/gcc/diagnostics/context.cc:1806
0x11dde16 decl_node
../../gcc/gcc/cp/module.cc:9089
0x11e3842 tree_node
../../gcc/gcc/cp/module.cc:10201
<snip>
Both of these cases are failing checking assertions for !DECL_LOCAL_DECL_P.
The issue is that the streaming logic assumes that we'll always first see a
local decl when streaming the function body, can stream by value at that point,
and then any other references within that function body can reference it by
back-ref.
However in this case, the template instantiations get streamed separately from
the function's body, so we ICE.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
[Bug 103524] [meta-bug] modules issue