Bug 69600 - [5 Regression] Incorrect use of copy-assignment instead of move assignment from function
Summary: [5 Regression] Incorrect use of copy-assignment instead of move assignment fr...
Status: RESOLVED DUPLICATE of bug 77334
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 5.3.0
: P3 normal
Target Milestone: 5.5
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-02-01 17:11 UTC by sshannin
Modified: 2024-08-27 15:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.5, 6.3.0, 7.0
Known to fail: 4.9.4, 5.4.0, 6.2.0
Last reconfirmed: 2017-01-17 00:00:00


Attachments
preprocessed source (92.75 KB, text/plain)
2016-02-01 17:11 UTC, sshannin
Details
Error output (1.25 KB, text/plain)
2016-02-01 17:12 UTC, sshannin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sshannin 2016-02-01 17:11:00 UTC
Created attachment 37541 [details]
preprocessed source

In some cases, it looks like the copy assignment operator is being used to store return values from a function instead of the move assignment operator.

This causes the compilation to fail because it tries to use the copy-assignment operator of some classes which may be movable only (unique_ptr).

Note that changing data_t to be either 'std::map<int, inner_data>' or 'std::map<int, value_t>' allows the code to compile.

Let me know if I can provide any more details that would be helpful.

gcc-5.3.0
x86_64-unknown-linux-gnu
Comment 1 sshannin 2016-02-01 17:12:31 UTC
Created attachment 37542 [details]
Error output

Error output from compiler.

Note it also fails to indicate which line the problematic instantiation is on.
Comment 2 Jonathan Wakely 2016-02-01 17:29:18 UTC
The value_type of your map is pair<const std::string, inner_data_t> an you can't move the first part of that pair, and you can't copy the second part of that pair, so you can't move or copy it.
Comment 3 sshannin 2016-02-01 17:42:14 UTC
(In reply to Jonathan Wakely from comment #2)
> The value_type of your map is pair<const std::string, inner_data_t> an you
> can't move the first part of that pair, and you can't copy the second part
> of that pair, so you can't move or copy it.

I'm not sure exactly what you mean/what the value_type typedef inside the map has to do with this.

Note that std::map<std::string, unique_ptr<int>> does seem to work here (where presumably value_type is pair<const string, unique_ptr<int>>).

Also, I just confirmed this did previously work on gcc-4.8.2
Comment 4 sshannin 2016-11-14 15:36:13 UTC
FWIW, this seems to be fixed on trunk. Still fails for at least 6.2, 5.4, and 4.9.4, but does compile with 7/trunk and 4.8.5

https://godbolt.org/g/hx9q4S
Comment 5 Jonathan Wakely 2017-01-17 17:52:50 UTC
This is a duplicate of Bug 77334 which is fixed for 5.5, 6.3 and 7.

*** This bug has been marked as a duplicate of bug 77334 ***
Comment 6 sshannin 2017-01-17 20:34:46 UTC
Thanks for the update : )
Comment 7 sshannin 2024-08-27 15:18:38 UTC
Comment on attachment 37541 [details]
preprocessed source


> #include <map>
> #include <memory>
> #include <string>
>typedef std::unique_ptr<int> inner_value_t;
>typedef std::map<int, inner_value_t> inner_data_t;
>
>typedef std::map<std::string, inner_data_t> data_t;
>
>
>data_t foo() {
>    return data_t{};
>}
>
>int main(int argc, char **argv)
>{
>
>    data_t d;
>    d = foo();
>    return 0;
>}