https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105761
Bug ID: 105761
Summary: ICE on hidden friend definition defined in base type
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: johelegp at gmail dot com
CC: johelegp at gmail dot com
Target Milestone: ---
See https://godbolt.org/z/v8arThEs1.
```C++
#include <type_traits>
template<class T> class X {
friend auto f(X);
};
template<class T, class = std::void_t<>> struct downcast_t { using type = void;
};
template<class T> struct downcast_t<T, std::void_t<decltype(f(X<T>{}))>> {
using type = decltype(f(X<T>{})); };
template<class T> using downcast = typename downcast_t<T>::type;
static_assert(std::is_same_v<void, downcast<int>>);
struct Y : X<long> {
friend auto f(X) { return 0L; }
};
static_assert(std::is_same_v<long, downcast<long>>);
```
```
<source>:4:18: warning: friend declaration 'auto f(X<T>)' declares a
non-template function [-Wnon-template-friend]
4 | friend auto f(X);
| ^
<source>:4:18: note: (if this is not what you intended, make sure the function
template has already been declared and add '<>' after the function name here)
<source>:15:20: internal compiler error: in push_template_decl, at
cp/pt.cc:6125
15 | friend auto f(X) { return 0L; }
| ^
0x21ffa39 internal_error(char const*, ...)
???:0
0x7452f3 fancy_abort(char const*, int, char const*)
???:0
0x82a0cd start_preparsed_function(tree_node*, tree_node*, int)
???:0
0x98cb8d c_parse_file()
???:0
0xb21d91 c_common_parse_file()
???:0
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.
```