This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/81232] compiler crashes for template function overload


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]