https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127207
Bug ID: 127207
Summary: [modules] ICE: tree check: expected template_decl,
have identifier_node in decl_value at
cp/module.cc:8390 - class template with a friend
declaration that forward-references a
function-template specialization
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jasio.lpn at gmail dot com
Target Milestone: ---
Minimal reproducer:
=== ICE.cppm ===
export module ICE;
export namespace ICE
{
template <typename T>
class Foo
{
friend auto createFoo<T>() -> Foo;
Foo(){}
};
template <typename T>
auto createFoo() -> Foo<T>
{
return Foo<T>{};
}
}
=== Command line ===
g++ -std=gnu++20 -fmodules -c -x c++ ICE.cppm
=== Output ===
internal compiler error: tree check: expected template_decl, have
identifier_node in decl_value, at cp/module.cc:8390
1 | export module ICE;
| ^~~~~~
0x2a2881f internal_error(char const*, ...)
../../source/gcc/diagnostic-global-context.cc:787
0x6795ed tree_check_failed(tree_node const*, char const*, int, char const*,
...)
../../source/gcc/tree.cc:9241
0x480ef0 tree_check(tree_node*, char const*, int, char const*, tree_code)
../../source/gcc/tree.h:3831
0x480ef0 decl_value
../../source/gcc/cp/module.cc:8388
0x960187 depset::hash::find_dependencies(module_state*)
../../source/gcc/cp/module.cc:15731
0x961390 module_state::write_begin(elf_out*, cpp_reader*, module_state_config&,
unsigned int&)
../../source/gcc/cp/module.cc:21113
0x96312d finish_module_processing(cpp_reader*)
../../source/gcc/cp/module.cc:23979
0x8d2d89 c_parse_final_cleanups()
../../source/gcc/cp/decl2.cc:6129
0xbae650 c_common_parse_file()
../../source/gcc/c-family/c-opts.cc:1455
/opt/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/cc1plus -quiet
-D_GNU_SOURCE Test.cppm -quiet -dumpbase Test.cppm -dumpbase-ext .cppm
-mtune=generic -march=x86-64 -std=gnu++20 -fmodules -o /tmp/ccUKCsZk.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
=== Workaround ===
When adding forward declarations into the exported namespace:
template <typename T>
class Foo;
template <typename T>
auto createFoo() -> Foo<T>;
the code compiles without issues.
=== Additional information ===
I am unsure how to classify this bug - whether it should be marked as
"ice-on-valid-code" or "ice-on-invalid-code". Although the original reproducer
is accepted by GCC and compiles fine outside of a module, the C++ standard
considers it ill-formed.
Additionally, this appears to be a regression, as g++ 16.2 compiles the
reproducer without any errors.