public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39126]  New: Missing "move" constructor call (C++0x rvalue references)
@ 2009-02-07 20:21 gbrammer at gmx dot de
  2009-05-07 19:05 ` [Bug c++/39126] " gbrammer at gmx dot de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gbrammer at gmx dot de @ 2009-02-07 20:21 UTC (permalink / raw)
  To: gcc-bugs

struct Foo {
    Foo(Foo && from) { }
    Foo() { }
    ~Foo() { }
/*private:
    Foo(const Foo & from) { }*/
};
Foo CreateFoo(bool b) {
  Foo f;
  if (b) return Foo();
  return f;
}
int main () {
    Foo f(CreateFoo(false));
}

The problem might also be a spurious destructor call. The symptom is that the
constructor without parameters is called once, the move constructor never and
the destructor twice. With the traditional copy constructor included, the
programme works as intended, with one additional move constructor call, but no
copy constructor calls. Without the "if (b) return Foo();" line the programme
also works.

I've tested with these builds and -std=gnu++0x:
g++-4.3 (Debian 4.3.2-1.1) 4.3.2
g++ (Debian 20090129-1) 4.4.0 20090129 (experimental) [trunk revision 143770]


-- 
           Summary: Missing "move" constructor call (C++0x rvalue
                    references)
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gbrammer at gmx dot de
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


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


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

* [Bug c++/39126] Missing "move" constructor call (C++0x rvalue references)
  2009-02-07 20:21 [Bug c++/39126] New: Missing "move" constructor call (C++0x rvalue references) gbrammer at gmx dot de
@ 2009-05-07 19:05 ` gbrammer at gmx dot de
  2009-05-07 19:09 ` pinskia at gcc dot gnu dot org
  2009-05-08 19:18 ` gbrammer at gmx dot de
  2 siblings, 0 replies; 4+ messages in thread
From: gbrammer at gmx dot de @ 2009-05-07 19:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from gbrammer at gmx dot de  2009-05-07 19:05 -------
Still happens with "g++-4.4 (Debian 4.4.0-4) 4.4.1".

Here's a version with printfs in the destructor and constructors:

extern "C" { int printf(const char *format, ...); }
struct Foo {
    Foo(Foo && from) { printf("move constructor\n"); }
    Foo() { printf("constructor\n"); }
    ~Foo() { printf("destructor\n"); }
/*private:
    Foo(const Foo & from) { printf("copy constructor\n"); }*/
};
Foo CreateFoo(bool b) {
  Foo f;
  if (b) return Foo();
  return f;
}
int main () {
    Foo f(CreateFoo(false));
}


-- 


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


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

* [Bug c++/39126] Missing "move" constructor call (C++0x rvalue references)
  2009-02-07 20:21 [Bug c++/39126] New: Missing "move" constructor call (C++0x rvalue references) gbrammer at gmx dot de
  2009-05-07 19:05 ` [Bug c++/39126] " gbrammer at gmx dot de
@ 2009-05-07 19:09 ` pinskia at gcc dot gnu dot org
  2009-05-08 19:18 ` gbrammer at gmx dot de
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-07 19:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-05-07 19:09 -------
Are you sure that an implicit copy constructor is not supposed to be created
here?


-- 


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


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

* [Bug c++/39126] Missing "move" constructor call (C++0x rvalue references)
  2009-02-07 20:21 [Bug c++/39126] New: Missing "move" constructor call (C++0x rvalue references) gbrammer at gmx dot de
  2009-05-07 19:05 ` [Bug c++/39126] " gbrammer at gmx dot de
  2009-05-07 19:09 ` pinskia at gcc dot gnu dot org
@ 2009-05-08 19:18 ` gbrammer at gmx dot de
  2 siblings, 0 replies; 4+ messages in thread
From: gbrammer at gmx dot de @ 2009-05-08 19:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from gbrammer at gmx dot de  2009-05-08 19:17 -------
Well, I am sure that it shouldn't be created, but rereading the spec
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html 12.8) I
noticed that this bug is not in g++, but by design.
I had hoped that rvalue references were a replacement for the ability to pass
temporaries to non-const references present in g++ up to version 4.1 and
Microsoft's C++ compilers, but apparently one has to be very very careful using
them. Well, at least I now only have to worry about the code, not the compiler.


-- 

gbrammer at gmx dot de changed:

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


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


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

end of thread, other threads:[~2009-05-08 19:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-07 20:21 [Bug c++/39126] New: Missing "move" constructor call (C++0x rvalue references) gbrammer at gmx dot de
2009-05-07 19:05 ` [Bug c++/39126] " gbrammer at gmx dot de
2009-05-07 19:09 ` pinskia at gcc dot gnu dot org
2009-05-08 19:18 ` gbrammer at gmx dot de

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).