Bug 46600 - Default move constructor copies array elements instead of moving them.
Summary: Default move constructor copies array elements instead of moving them.
Status: RESOLVED DUPLICATE of bug 46103
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-22 12:24 UTC by Simon Hill
Modified: 2010-11-22 23:48 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Complete example code. Compile with 4.6 or higher using -std=c++0x. (180 bytes, text/x-c++src)
2010-11-22 12:24 UTC, Simon Hill
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hill 2010-11-22 12:24:13 UTC
Created attachment 22482 [details]
Complete example code. Compile with 4.6 or higher using -std=c++0x.

N3126: § 12.8.17 [move constructors]:
--(3): "an array is initialized by moving each element in the manner appropriate to the element type"

If you have a class with a member array and you call the default move constructor for said class, the move constructor COPIES said array elements. From what the standard says, it seems it should MOVE these elements.



VERSION: 4.6.0 20100529 (experimental) (GCC)
4.5.1 is unable to explicitly default the move constructor.
I don't have any other functional versions between these two.
NOTE: I have added Pedro Lamarão's patch http://gcc.gnu.org/ml/gcc-patches/2007-04/msg00620.html to my 4.6.0 but I can't see this affecting anything.

TARGET: x86_64-unknown-linux-gnu
SYSTEM: Core2Duo / Ubuntu(64) 10.4.

ATTACHMENT:
Compiles OK with -std=c++0x.
OUTPUT:
copy
copy
move
PROBLEM:
According to the C++ spec (ver N3126), I think the first 2 "copy"s should be "move"s.
Comment 1 Jonathan Wakely 2010-11-22 12:54:04 UTC
dup of PR 46103 which was fixed last month 

if you want to test the latest development version you shouldn't use a build from 6 months ago

*** This bug has been marked as a duplicate of bug 46103 ***
Comment 2 Simon Hill 2010-11-22 23:21:04 UTC
Sorry about that.
All that work and I didn't even notice my test GCC was the wrong one.
Comment 3 Jonathan Wakely 2010-11-22 23:48:47 UTC
you should definitely try a recent snapshot, there's been a lot of work on move support and g++ is pretty close to the n3126 definitions (although those aren't set in stone yet and might change)