[Bug c++/49476] New: Complex functions returning references (not following C++ standard)

2011-06-20 Thread basil.al-dajane at intel dot com
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)


[Bug c++/49476] Complex functions returning references (not following C++ standard)

2011-06-20 Thread basil.al-dajane at intel dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

--- Comment #1 from Basil  2011-06-20 
17:22:12 UTC ---
Created attachment 24567
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24567
Reproducer program


[Bug c++/49476] Complex functions returning references (not following C++ standard)

2011-06-20 Thread basil.al-dajane at intel dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

--- Comment #2 from Basil  2011-06-20 
17:22:36 UTC ---
Created attachment 24568
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24568
Patch to fix issue


[Bug libstdc++/49476] Complex functions returning references (not following C++ standard)

2011-06-20 Thread basil.al-dajane at intel dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

--- Comment #4 from Basil  2011-06-20 
18:10:39 UTC ---
The change doesn't fix the issue, as it is a solution for when -std=c++0x is
specified.

(In reply to comment #3)
> Changed by http://gcc.gnu.org/ml/libstdc++/2004-01/msg00091.html
> c.f.
> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#387
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1589.html
> http://gcc.gnu.org/ml/libstdc++/2008-05/msg00120.html