http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476
Summary: Complex functions returning references (not following
C++ standard)
Product: gcc
Version: 4.5.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: basil.al-daj...@intel.com
In the C++ standard definition, section 26.2.7, std::real() and std::imag() are
defined to be:
template T real (const complex & x)
template T imag (const complex & x)
GCC version 4.5.2, these functions return references, unless -std=c++0x is
specified. If a specialization of std::complex returns values for real() and
imag(), an error during compilation will occur. When compiling the attached
reproducer (complex.cpp), the following error occurs:
$ g++ complex.cpp -o complex -Wall -Wextra
In file included from complex.cpp:2:0:
/usr/include/c++/4.5/complex: In function ‘_Tp& std::real(std::complex<_Tp>&)
[with _Tp = f32]’:
complex.cpp:42:22: instantiated from here
/usr/include/c++/4.5/complex:544:23: error: invalid initialization of non-const
reference of type ‘f32&’ from an rvalue of type ‘value_type’
/usr/include/c++/4.5/complex: In function ‘_Tp& std::imag(std::complex<_Tp>&)
[with _Tp = f32]’:
complex.cpp:43:22: instantiated from here
/usr/include/c++/4.5/complex:554:23: error: invalid initialization of non-const
reference of type ‘f32&’ from an rvalue of type ‘value_type’
Fix:
A patch has been attached to this report (along with an example that would
trigger the error)
Additional System Information:
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.5 --enable-shared --enable-multiarch
--with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/i386-linux-gnu
--enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default
--with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)