public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters
@ 2011-05-09 10:14 bisqwit at iki dot fi
  2011-05-09 10:46 ` [Bug libstdc++/48933] " paolo.carlini at oracle dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-09 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Infinite recursion in tr1/cmath functions with complex
                    parameters
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bisqwit@iki.fi
                CC: warp@iki.fi


All of the function calls in this example code produce a stack overflow due to
infinite recursion, regardless of optimization level.
Compile with: g++ code.cc
Tested on the following gcc versions: 4.2.4  4.3.5  4.4.6  4.5.2  4.6.1
No compiler warnings or errors are emitted. (Tried even -Wall -W -pedantic
-ansi).

Does not happen on gcc 4.0.4, because tr1/cmath is unavailable.

#include <tr1/cmath>
#include <complex>
int main()
{
    std::tr1::tgamma( std::complex<double> (0.5, 0.0) );
    std::tr1::cbrt( std::complex<double> (0.5, 0.0) );
    std::tr1::asinh( std::complex<double> (0.5, 0.0) );
    std::tr1::acosh( std::complex<double> (1.5, 0.0) );
    std::tr1::atanh( std::complex<double> (0.5, 0.0) );
    std::tr1::erf( std::complex<double> (0.5, 0.0) );
    std::tr1::hypot( std::complex<double> (1.0, 0.0) ,
                     std::complex<double> (1.0, 0.0) );
    std::tr1::logb( std::complex<double> (0.5, 0.0) );
    std::tr1::round( std::complex<double> (0.5, 0.0) );
    std::tr1::trunc( std::complex<double> (0.5, 0.0) );
}

The bug can be traced to all functions in tr1/cmath that look like this:

  template<typename _Tp>
    inline typename __gnu_cxx::__promote<_Tp>::__type
    cbrt(_Tp __x) 
    {
      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
      return cbrt(__type(__x)); // <-- infinite recursion here
    }


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-12-19  1:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
2011-05-09 10:46 ` [Bug libstdc++/48933] " paolo.carlini at oracle dot com
2011-05-09 10:49 ` redi at gcc dot gnu.org
2011-05-09 11:00 ` bisqwit at iki dot fi
2011-05-09 11:06 ` redi at gcc dot gnu.org
2011-05-09 11:08 ` paolo.carlini at oracle dot com
2011-05-09 11:17 ` paolo.carlini at oracle dot com
2011-05-09 15:46 ` paolo.carlini at oracle dot com
2011-05-09 15:48 ` paolo at gcc dot gnu.org
2011-12-19  2:22 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).