#1094919 modules: ICE when initializing a stream using a function template returning a stream

Package:
g++-14
Source:
g++-14
Description:
GNU C++ compiler
Submitter:
Frank B. Brokken
Date:
2025-02-12 10:09:01 UTC
Severity:
normal
#1094919#5
Date:
2025-02-01 13:16:05 UTC
From:
To:
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 ***
#1094919#10
Date:
2025-02-12 10:06:02 UTC
From:
To:
thanks for filing all these issues related to modules.  Please could you
recheck these with gcc-15 from experimental, or gcc-snapshot from unstable?

After doing that, I would appreciate it, if you could file bug reports
in the upstream bug tracker.  All these reports seem to be upstream
issues. When doing that, please also set the Forwarded attribute in the
Debian bug tracker.