http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56085



             Bug #: 56085

           Summary: Unsafe negation in C++03 pow(complex,int)

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: libstdc++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: gli...@gcc.gnu.org





template<typename _Tp>

    inline complex<_Tp>

    pow(const complex<_Tp>& __z, int __n)

    {

      return __n < 0

        ? complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -__n)

        : std::__complex_pow_unsigned(__z, __n);



If I understand correctly, -__n is undefined behavior for INT_MIN, and this

should use -(unsigned)__n instead to be safe. This is not just theoretical,

other projects had to do similar changes because gcc starting with 4.7 would

produce wrong code otherwise.

Reply via email to