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: [email protected]
ReportedBy: [email protected]
CC: [email protected]
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
}