This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/81232] compiler crashes for template function overload
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 27 Jun 2017 15:05:13 +0000
- Subject: [Bug c++/81232] compiler crashes for template function overload
- Auto-submitted: auto-generated
- References: <bug-81232-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81232
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ice-on-invalid-code
Status|UNCONFIRMED |NEW
Last reconfirmed| |2017-06-27
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC should not crash, but your code is invalid (and also crashes Clang):
The problem is that you've defined the second overload with a non-deducible
template parameter:
template<int N, typename T> static constexpr T ipow(T x, int_<-1>)
{
return static_cast<T>(1) / ipow<-N>(x, int_<-N>());
}
This cannot deduce N, so can only be called with a explicit argument, like
ipow<-1> or ipow<-1, int>.
That means when you call ipow(2, int_<-1>) you invoke the third overload, which
recursively tries to call itself with more and more negative values of N, until
the compiler dies.