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

            Bug ID: 105859
           Summary: ICE in instantiate_decl
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sam at gentoo dot org
  Target Milestone: ---

Originally reported downstream in Gentoo (https://bugs.gentoo.org/849791) by
Toralf Förster (toralf). Noticed when building dev-games/wfmath-1.0.2.

(Ionen in the downstream bug mentions 11.3.0 is fine, but it fails for me with
11.3.1 20220602 too.)

Reproducer:
```
template <int = 3> struct Vector {
  friend Vector Cross(const Vector &, const Vector &);
  Vector &rotate(const int &);
};
template <> Vector<> &Vector<>::rotate(const int &) {
  Vector __trans_tmp_8 = Cross(__trans_tmp_8, *this);
}
Vector<> Cross(const Vector<> &, const Vector<> &) {}
```

Seems to not require any specific flags:
```
$ g++ foo.ii
foo.ii:3:53: warning: friend declaration ‘Vector<<anonymous> > Cross(const
Vector<<anonymous> >&, const Vector<<anonymous> >&)’ declares a non-template
function [-Wnon-template-friend]
    3 |   friend Vector Cross(const Vector &, const Vector &);
      |                                                     ^
foo.ii:3:53: note: (if this is not what you intended, make sure the function
template has already been declared and add ‘<>’ after the function name here)
foo.ii: In member function ‘Vector<<anonymous> >& Vector<<anonymous>
>::rotate(const int&) [with int <anonymous> = 3]’:
foo.ii:8:1: warning: no return statement in function returning non-void
[-Wreturn-type]
    8 | }
      | ^
foo.ii: In function ‘Vector<> Cross(const Vector<>&, const Vector<>&)’:
foo.ii:9:53: warning: no return statement in function returning non-void
[-Wreturn-type]
    9 | Vector<> Cross(const Vector<> &, const Vector<> &) {}
      |                                                     ^
foo.ii: At global scope:
foo.ii:7:31: internal compiler error: Segmentation fault
    7 |   Vector __trans_tmp_8 = Cross(__trans_tmp_8, *this);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~
0xd06f86 crash_signal
       
/usr/src/debug/sys-devel/gcc-12.1.1_p20220604/gcc-12-20220604/gcc/toplev.cc:322
0x163c55e instantiate_decl(tree_node*, bool, bool)
       
/usr/src/debug/sys-devel/gcc-12.1.1_p20220604/gcc-12-20220604/gcc/cp/pt.cc:26488
0x130a940 instantiate_pending_templates(int)
       
/usr/src/debug/sys-devel/gcc-12.1.1_p20220604/gcc-12-20220604/gcc/cp/pt.cc:26809
0x1303070 c_parse_final_cleanups()
       
/usr/src/debug/sys-devel/gcc-12.1.1_p20220604/gcc-12-20220604/gcc/cp/decl2.cc:5128
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
```

```
$ g++ --version
g++ (Gentoo Hardened 12.1.1_p20220604 p7) 12.1.1 20220604
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

Reply via email to