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

            Bug ID: 125676
           Summary: ICE in duplicate_decls, at cp/decl.cc:3132
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ice-checking, ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alexey.saldyrkine at gmail dot com
  Target Milestone: ---

If a friend function was defined in a template class A and declared in a
template class B, ICE will occur upon the second instantiation of class B.

ICE occurs if checking is enabled on gcc versions: 12.4 - 17.0.


Godbolt link: https://godbolt.org/z/bMjdjEefj

```
template<int>
struct A{
    friend void f(){}
};

template<int>
struct B{
    friend void f();
};

template struct A<0>;    // define f
template struct B<0>;    // first declaration of f 
template struct B<1>;    // second declaration of f, ICE here

int main(){}
```
Error:
```
<source>: In instantiation of 'struct B<1>':
<source>:13:17:   required from here
   13 | template struct B<1>;    // second declaration of f, ICE here
      |                 ^~~~
<source>:8:17: internal compiler error: in duplicate_decls, at cp/decl.cc:3132
    8 |     friend void f();
      |                 ^
0x29f5248 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x29e9e8b internal_error(char const*, ...)
        ???:0
0xb33f5c fancy_abort(char const*, int, char const*)
        ???:0
0xd0e813 pushdecl(tree_node*, bool)
        ???:0
0xd0fdde pushdecl_namespace_level(tree_node*, bool)
        ???:0
0xdf403b instantiate_class_template(tree_node*)
        ???:0
0xdec915 do_type_instantiation(tree_node*, tree_node*, int)
        ???:0
0xd87993 c_parse_file()
        ???:0
0xf17559 c_common_parse_file()
        ???:0
/cefs/97/97a4e8c0f997d8d8242b8779_gcc-trunk-20260608/bin/../libexec/gcc/x86_64-linux-gnu/17.0.0/cc1plus
-quiet -imultiarch x86_64-linux-gnu -iprefix
/cefs/97/97a4e8c0f997d8d8242b8779_gcc-trunk-20260608/bin/../lib/gcc/x86_64-linux-gnu/17.0.0/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -mtune=generic -march=x86-64 -g -fdiagnostics-color=always
-fno-verbose-asm -o /app/output.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```
  • [Bug c++/125676] New: ICE ... alexey.saldyrkine at gmail dot com via Gcc-bugs

Reply via email to