https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115801

            Bug ID: 115801
           Summary: [modules] segfault instantiating a template with a
                    templated friend declaration referring to an
                    unexported template using a qualified name
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

// test.cpp
module;
export module test;

template<class>
struct Foo {};

export
template<class F>
class Bar
{
private:
    template<class>
    friend struct ::Foo;  // #1
};

// main.cpp
import test;

int main() {
  Bar<int> x;
}

On compiler explorer: https://godbolt.org/z/4MT58K3nj

/opt/compiler-explorer/gcc-snapshot/bin/g++   -fdiagnostics-color=always -Wall
-Wextra -g -std=gnu++20 -MD -MT CMakeFiles/demo.dir/main.cpp.o -MF
CMakeFiles/demo.dir/main.cpp.o.d -fmodules-ts
-fmodule-mapper=CMakeFiles/demo.dir/main.cpp.o.modmap -MD -fdeps-format=p1689r5
-x c++ -o CMakeFiles/demo.dir/main.cpp.o -c /app/main.cpp
In module test, imported at /app/main.cpp:2:
test.cpp: In instantiation of 'class Bar@test<int>':
main.cpp:5:12:   required from here
    5 |   Bar<int> x;
      |            ^
test.cpp:5:8: internal compiler error: Segmentation fault
    5 | struct Foo {};
      |        ^~~
0x26df0a5 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, int, char const*, __va_list_tag (*) [1],
diagnostic_t)
        ???:0
0x26ecc52 internal_error(char const*, ...)
        ???:0
0xcd19e8 instantiate_class_template(tree_node*)
        ???:0
0xb2a559 start_decl_1(tree_node*, bool)
        ???:0
0xb4d25f start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
        ???:0
0xc708aa c_parse_file()
        ???:0
0xdc7489 c_common_parse_file()
        ???:0

Removing the :: qualification at #1 or exporting Foo makes this work.

Reply via email to