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

            Bug ID: 110523
           Summary: [14 Regression] ICE in redeclare_class_template, at
                    cp/pt.cc:6391 on json-3.11.2
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

Noticed ICE on r14-2233-gfca6d9c12f5bf0 when was building json-3.11.2 package.

Extracted reproducer:

// $ cat bug.cpp
template <typename, typename> struct adl_serializer;

template <template <typename, typename> class = adl_serializer>
class basic_json;

template <typename> struct json_pointer {
  template <template <typename, typename> class> friend class basic_json;
};
template <template <typename, typename> class> struct basic_json {
  using json_pointer = json_pointer<int>;
};
basic_json<>::json_pointer __trans_tmp_1_DOCTEST_ANON_FUNC_2() {
  json_pointer<basic_json<>> ptr_j;
}

$ g++ -c bug.cpp
bug.cpp:10:9: warning: declaration of 'using basic_json<
<template-parameter-1-1> >::json_pointer = struct json_pointer<int>' changes
meaning of 'json_pointer' [-Wchanges-meaning]
   10 |   using json_pointer = json_pointer<int>;
      |         ^~~~~~~~~~~~
bug.cpp:10:24: note: used here to mean 'struct json_pointer<int>'
   10 |   using json_pointer = json_pointer<int>;
      |                        ^~~~~~~~~~~~~~~~~
bug.cpp:6:28: note: declared here
    6 | template <typename> struct json_pointer {
      |                            ^~~~~~~~~~~~
bug.cpp: In instantiation of 'struct json_pointer<basic_json<> >':
bug.cpp:13:30:   required from here
bug.cpp:7:63: internal compiler error: in redeclare_class_template, at
cp/pt.cc:6391
    7 |   template <template <typename, typename> class> friend class
basic_json;
      |                                                              
^~~~~~~~~~
0x708b6c redeclare_class_template(tree_node*, tree_node*, tree_node*)
        ../../source/gcc/cp/pt.cc:6391
0x8fe749 tsubst_friend_class
        ../../source/gcc/cp/pt.cc:11590
0x8fe749 instantiate_class_template(tree_node*)
        ../../source/gcc/cp/pt.cc:12446
0x9398ed complete_type(tree_node*)
        ../../source/gcc/cp/typeck.cc:138
0x7c49e2 start_decl_1(tree_node*, bool)
        ../../source/gcc/cp/decl.cc:5980
0x7de3e9 start_decl_1(tree_node*, bool)
        ../../source/gcc/cp/decl.cc:5946
0x7de3e9 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
        ../../source/gcc/cp/decl.cc:5946
0x8b70b7 cp_parser_init_declarator
        ../../source/gcc/cp/parser.cc:22951
0x88f971 cp_parser_simple_declaration
        ../../source/gcc/cp/parser.cc:15435
0x891520 cp_parser_declaration_statement
        ../../source/gcc/cp/parser.cc:14516
0x891c39 cp_parser_statement
        ../../source/gcc/cp/parser.cc:12574
0x892d6d cp_parser_statement_seq_opt
        ../../source/gcc/cp/parser.cc:13000
0x892e0f cp_parser_compound_statement
        ../../source/gcc/cp/parser.cc:12952
0x8b5881 cp_parser_function_body
        ../../source/gcc/cp/parser.cc:25372
0x8b5881 cp_parser_ctor_initializer_opt_and_function_body
        ../../source/gcc/cp/parser.cc:25423
0x8b6a4e cp_parser_function_definition_after_declarator
        ../../source/gcc/cp/parser.cc:32058
0x8b7dcc cp_parser_function_definition_from_specifiers_and_declarator
        ../../source/gcc/cp/parser.cc:31975
0x8b7dcc cp_parser_init_declarator
        ../../source/gcc/cp/parser.cc:22831
0x88f971 cp_parser_simple_declaration
        ../../source/gcc/cp/parser.cc:15435
0x8c1ddb cp_parser_declaration
        ../../source/gcc/cp/parser.cc:15121

$ g++ -v
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-14.0.0/bin/g++
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-14.0.0/libexec/gcc/x86_64-unknown-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 99999999 (experimental) (GCC)

Reply via email to