This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Incompatible type of std::imag function


In this patch http://gcc.gnu.org/ml/gcc-patches/2004-01/msg00866.html
the type signatures of the std::imag and std::real functions were changed to return references. This seems to be incompatible with the standard (The C++ Programming Language, sec 22.5). In particular, the following code:


double (*c2r)(const std::complex<double>&) = std::imag;

should compile cleanly, but currently fails:

test.cc: In function ‘int main()’:
test.cc:4: error: no matches converting function ‘imag’ to type ‘double (*)(const struct std::complex<double>&)’
/usr/include/c++/4.0.2/complex:541: error: candidates are: template<class _Tp> _Tp& std::imag(std::complex<_Tp>&)
/usr/include/c++/4.0.2/complex:546: error: template<class _Tp> const _Tp& std::imag(const std::complex<_Tp>&)
make: *** [test] Error 1


A similar issue was reported last November regarding the corresponding member functions of std::complex (http://gcc.gnu.org/ml/libstdc++/2005-11/msg00162.html). However, as far as I am aware, there should be no issue with taking function pointers of templatized non-member functions. Any thoughts?

Thanks,

Gene Novark
Research Assistant
Dept. of Computer Science
University of Massachusetts Amherst


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