Bug#1094919: modules: ICE when initializing a stream using a function template returning a stream
Package: g++-14
Version: 14.2.0-12
Severity: normal
Dear Maintainer,
* What exactly did you do?
First I prepared in /usr/include/c++/14/ string.gcm and fstream.gcm,
calling
g++ --std=c++26 -Wall -fmodules-ts -x c++-system-header string
and
g++ --std=c++26 -Wall -fmodules-ts -x c++-system-header fstream
followed by
mv gcm.cache/usr/include/c++/14/*.gcm .
so they're located in /usr/include/c++/14/ and can be imported.
Then I wrote the following source file (e.g., factory.cc, stripped down to its
bare essentials (commented lines are covered below):
---------------------------------------------------------------------
//#include <string> // #1
//#include <fstream> //
export module Factory; // #2
export import <string>; //
export import <fstream>; //
export //
{ //
template <typename Stream>
Stream streamFactory(std::string const &name)
{
return Stream{ name };
}
std::ifstream factory(std::string const &name)
{
return std::ifstream{ name };
}
void consume(std::string const &name)
{
[[maybe_unused]]
std::ifstream in{ streamFactory<std::ifstream>(name) }; // #3
// std::ifstream in; // #4
// in = streamFactory<std::ifstream>(name); //
// std::ifstream in{ factory(name) }; // #5
}
} // NOTE: #2
---------------------------------------------------------------------
In its directory I defined a sub-directory gcm.cache having a softlink
usr -> /usr
so the module-compiled headers are available.
When compiling factory.cc using
g++ -freport-bug --std=c++26 -Wall -fmodules-ts -c factory.cc
an internal compiler error is reported:
----------------------------------------------------------------------------------------------
factory.cc: In function â<80><98>void consume(const std::string&)â<80><99>:
factory.cc:24:66: internal compiler error: in simplify_aggr_init_expr, at cp/semantics.cc:4953
24 | std::ifstream in{ streamFactory<std::ifstream>(name) }; // #3
| ^
0x1406bd1 internal_error(char const*, ...)
???:0
0x13ffe27 fancy_abort(char const*, int, char const*)
???:0
0x1694409 cp_gimplify_expr(tree_node**, gimple**, gimple**)
???:0
0x157d6fb gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
???:0
0x157e5cd gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
???:0
0x157e759 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
???:0
0x157ec0a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
???:0
0x1573c56 gimplify_body(tree_node*, bool)
???:0
0x1572ce8 gimplify_function_tree(tree_node*)
???:0
0x157181f cgraph_node::analyze()
???:0
0x1aca30d symbol_table::finalize_compilation_unit()
???:0
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-14/README.Bugs> for instructions.
----------------------------------------------------------------------------------------------
If, instead of line #3 the two lines #4 are used or line #5 is used
compilation ends without errors.
Also, if line #3 and the lines #1 are activated, but the module-related lines
(#2) are removed, using a non-module compilation:
g++ --std=c++26 -Wall -c factory.cc
compilation successfully ends.
Apparently using module-compilation initializing a std::ifstream using a
function template factory function results in the internal compiler error.
* What outcome did you expect instead?
I expected that the function template returning a stream could be used to
construct a stream object, like it's possible with a non-module compilation
and with a module compilation using a plain factory function instead of a
factory function which is a function template.
*** End of the template - remove these template lines ***
-- System Information:
Debian Release: trixie/sid
APT prefers testing
APT policy: (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 6.12.10-amd64 (SMP w/2 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages g++-14 depends on:
ii g++-14-x86-64-linux-gnu 14.2.0-12
ii gcc-14 14.2.0-12
ii gcc-14-base 14.2.0-12
g++-14 recommends no packages.
Versions of packages g++-14 suggests:
pn g++-14-multilib <none>
pn gcc-14-doc <none>
-- no debconf information
Reply to: