This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Q. about GDR's addition of complex-accessor overloads.
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: jan at etpmod dot phys dot tue dot nl
- Cc: libstdc++ at gcc dot gnu dot org
- Date: 10 Nov 2005 09:18:56 +0100
- Subject: Re: Q. about GDR's addition of complex-accessor overloads.
- References: <200511100835.37715.jan@etpmod.phys.tue.nl>
Jan van Dijk <jan@etpmod.phys.tue.nl> writes:
| L.S,
|
| With patch http://gcc.gnu.org/ml/gcc-patches/2004-01/msg00866.html Gabriel Dos
| Reis changed the real() and imag() members of std::complex<T>. These were
| changed to return const references, while non-const overloads were added to
| return unqualified references.
|
| This causes problem with the following (reduced) program:
|
| #include <complex>
| #include <functional>
|
| typedef std::complex<double> complex;
|
| void foo()
| {
| std::mem_fun_ref(&complex::real);
| }
|
| which gives me, with today's trunk:
|
| ./cmplx_acc_overload.cpp: In function ‘void foo()’:
| ./cmplx_acc_overload.cpp:10: error: call of overloaded
| ‘mem_fun_ref(<unresolved overloaded function type>)’ is ambiguous
| /home/jan/local/gcc-head/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../include/c++/4.1.0/bits/stl_function.h:723:
| note: candidates are: std::mem_fun_ref_t<_Ret, _Tp> std::mem_fun_ref(_Ret
| (_Tp::*)()) [with _Ret = double&, _Tp = std::complex<double>]
| /home/jan/local/gcc-head/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../include/c++/4.1.0/bits/stl_function.h:728:
| note: std::const_mem_fun_ref_t<_Ret, _Tp>
| std::mem_fun_ref(_Ret (_Tp::*)()const) [with _Ret = const double&, _Tp =
| std::complex<double>]
|
| Translated to English this means: should I create a const_mem_fun_ref_t with
| complex::real() const, or a a mem_fun_ref_t with the non-const real()
| overload?
|
| Since the standard (26.2.2, or more particular: 26.2.3) mentions only one
| real() and imag(), it is my belief that the above test program is correct,
| and gcc's libstdc++ is off-specs.
|
| Any thoughts?
|
| In case this issue has already been discussed, I apologize for not googling
| well enough and a pointer to the previous discourse would be appreciated.
The changes were made subsequent to a DR I reported and LWG agreed upon
the suggested resolutions.
Then a distraction happened.
The issue you're reporting is a fundamental flaw with mem_fun_ref
rather than with complex::real being overloaded on const.
BTW, as a general rule, it is not a portable code to take the address
of a non-virtual member function of a standard class -- the compiler
may or may not accept it.
-- Gaby