[Bug libstdc++/51013] New: complex::{imag,real}() should maintain lvalue-returning extension in C++11

jyasskin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 7 21:10:00 GMT 2011


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

             Bug #: 51013
           Summary: complex::{imag,real}() should maintain
                    lvalue-returning extension in C++11
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jyasskin@gcc.gnu.org


In C++98, libstdc++ has an extension to return T& from complex<T>::real() and
::imag() (introduced in r75680). Paolo removed this extension for C++11 in
r135878 citing
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#387. However, the
point of DR387 was to increase the amount of access complex<> provides to its
internals, not to remove existing extensions providing such access.

Removing this extension affects code that passes references to the real or
imaginary parts of a complex number to other routines. While such code can
generally be rewritten in a straightforward way, it seems like an unnecessary
hurdle that should be avoided given all the other changes needed for C++11
compatibility.

The DR387-provided reinterpret_cast<> way of getting access to the addresses
would work if we were migrating to C++11 atomically, but that's impossible in a
large codebase. I believe the reinterpret_cast produces undefined behavior in
C++98 because of the aliasing violation, so we can't use it in code that needs
to be correct in both versions of the language.

So I think the extension should be reinstated.



More information about the Gcc-bugs mailing list