[Qt-interest] Qt code compiles fine on mscv9.0 but failed with gcc

Thiago Macieira thiago at kde.org
Wed Jan 26 17:32:29 CET 2011


Interestingly, with this C++0x addition:

> struct Foo
> {
>     QString &s;
>     Foo(QString &s) : s(s) {}
	Foo(QString &&s) : s(s) {}

> };
> 
> void function()
> {
>     Foo f(QString("abc"));
>     f.s = "def";
> }

The code compiles just fine, but is clearly broken. A simple disassembly with a 
stub QString proves it (ARM assembly for simplicity):

        add     r5, sp, #4
        ldr     r1, .L4
        mov     r0, r5
        bl      _ZN7QStringC1EPKc

Call the QString(const char*) constructor with r0 (the "this" argument)=sp+4.

        mov     r0, r5
        bl      _ZN7QStringD1Ev

Call the QString destructor with this=sp+4.

        mov     r0, sp
        ldr     r1, .L4+4
        bl      _ZN7QStringC1EPKc

Call the QString(const char*) constructor with this=sp.

        mov     r0, r5
        mov     r1, sp
        bl      _ZN7QStringaSERKS_

Call operator== with this=sp+4 and other=sp (in r1). Note how the "this" 
object has already been destroyed.

        mov     r0, sp
        mov     r4, sp
        bl      _ZN7QStringD1Ev

I'm not sure what C++0x says about initialising an lvalue ref from an rvalue 
ref.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110126/37a198bf/attachment.bin 


More information about the Qt-interest-old mailing list