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

            Bug ID: 124691
           Summary: ICE in duplicate_decls with friend function
                    redeclaration in class template
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: error-recovery, ice-checking, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: attackerj1113 at gmail dot com
  Target Milestone: ---

The following code causes ICE out on x86-64 gcc since version 11.4(assertions)
and reproducible on trunk:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<class T>
struct A {
  friend int f(bool) { return 0; }
  friend int f(bool);
};

A<int> a;
A<char> b;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://godbolt.org/z/5TzWr7PWd

After diagnosing a redefinition of a friend function declared inside a class
template, GCC crashes with an internal compiler error in duplicate_decls upon
multiple instantiations.

Output:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In instantiation of 'struct A<char>':
<source>:8:9:   required from here
<source>:3:14: error: redefinition of 'int f(bool)'
    3 |   friend int f(bool) { return 0; }
      |              ^
<source>:4:14: note: 'int f(bool)' previously declared here
    4 |   friend int f(bool);
      |              ^
<source>:4:14: internal compiler error: in duplicate_decls, at cp/decl.c:2593
0x20ac1ac internal_error(char const*, ...)
        ???:0
0xb33227 fancy_abort(char const*, int, char const*)
        ???:0
0xc9f516 pushdecl_namespace_level(tree_node*, bool)
        ???:0
0xd4d956 instantiate_class_template(tree_node*)
        ???:0
0xbd16eb start_decl_1(tree_node*, bool)
        ???:0
0xbf1c90 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
        ???:0
0xcf18a4 c_parse_file()
        ???:0
0xe1eb85 c_common_parse_file()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

Reply via email to