public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49476] New: Complex functions returning references (not following C++ standard)
@ 2011-06-20 17:21 basil.al-dajane at intel dot com
  2011-06-20 17:22 ` [Bug c++/49476] " basil.al-dajane at intel dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: basil.al-dajane at intel dot com @ 2011-06-20 17:21 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: basil.al-dajane@intel.com


In the C++ standard definition, section 26.2.7, std::real() and std::imag() are
defined to be:
  template <class T> T real (const complex <T>& x)
  template <class T> T imag (const complex <T>& 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)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/49476] Complex functions returning references (not following C++ standard)
  2011-06-20 17:21 [Bug c++/49476] New: Complex functions returning references (not following C++ standard) basil.al-dajane at intel dot com
  2011-06-20 17:22 ` [Bug c++/49476] " basil.al-dajane at intel dot com
@ 2011-06-20 17:22 ` basil.al-dajane at intel dot com
  2011-06-20 17:56 ` [Bug libstdc++/49476] " redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: basil.al-dajane at intel dot com @ 2011-06-20 17:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/49476] Complex functions returning references (not following C++ standard)
  2011-06-20 17:21 [Bug c++/49476] New: Complex functions returning references (not following C++ standard) basil.al-dajane at intel dot com
@ 2011-06-20 17:22 ` basil.al-dajane at intel dot com
  2011-06-20 17:22 ` basil.al-dajane at intel dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: basil.al-dajane at intel dot com @ 2011-06-20 17:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

--- Comment #1 from Basil <basil.al-dajane at intel dot com> 2011-06-20 17:22:12 UTC ---
Created attachment 24567
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24567
Reproducer program


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/49476] Complex functions returning references (not following C++ standard)
  2011-06-20 17:21 [Bug c++/49476] New: Complex functions returning references (not following C++ standard) basil.al-dajane at intel dot com
  2011-06-20 17:22 ` [Bug c++/49476] " basil.al-dajane at intel dot com
  2011-06-20 17:22 ` basil.al-dajane at intel dot com
@ 2011-06-20 17:56 ` redi at gcc dot gnu.org
  2011-06-20 18:10 ` basil.al-dajane at intel dot com
  2011-06-20 18:21 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-06-20 17:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-06-20 17:56:24 UTC ---
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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/49476] Complex functions returning references (not following C++ standard)
  2011-06-20 17:21 [Bug c++/49476] New: Complex functions returning references (not following C++ standard) basil.al-dajane at intel dot com
                   ` (2 preceding siblings ...)
  2011-06-20 17:56 ` [Bug libstdc++/49476] " redi at gcc dot gnu.org
@ 2011-06-20 18:10 ` basil.al-dajane at intel dot com
  2011-06-20 18:21 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: basil.al-dajane at intel dot com @ 2011-06-20 18:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

--- Comment #4 from Basil <basil.al-dajane at intel dot com> 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/49476] Complex functions returning references (not following C++ standard)
  2011-06-20 17:21 [Bug c++/49476] New: Complex functions returning references (not following C++ standard) basil.al-dajane at intel dot com
                   ` (3 preceding siblings ...)
  2011-06-20 18:10 ` basil.al-dajane at intel dot com
@ 2011-06-20 18:21 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-06-20 18:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-06-20 18:21:01 UTC ---
I don't think we should fix now, after 7 years, the return type of std::real
and std::imag in C++03 mode, because this would cause serious ABI problems when
objects build with pre- and post- <complex> header are linked together. Indeed,
that's exactly why I changed the return-type only in C++0x mode, where we have
leeway.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-20 18:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-20 17:21 [Bug c++/49476] New: Complex functions returning references (not following C++ standard) basil.al-dajane at intel dot com
2011-06-20 17:22 ` [Bug c++/49476] " basil.al-dajane at intel dot com
2011-06-20 17:22 ` basil.al-dajane at intel dot com
2011-06-20 17:56 ` [Bug libstdc++/49476] " redi at gcc dot gnu.org
2011-06-20 18:10 ` basil.al-dajane at intel dot com
2011-06-20 18:21 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).