https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87057
Bug ID: 87057
Summary: in compilation error, gcc should note about deleted
copy-constructor
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Hi-Angel at yandex dot ru
Target Milestone: ---
When, in a code, a copy-constructor deleted but used, GCC issues an absolutely
unhelpful message that it couldn't convert the argument. "Why can't it?". It's
extremely difficult to diagnose — e.g. in my case I had to go down from a
project code to the minimal example below before I could figure it out. There's
really no other way, except as of magically guessing that some of fields used
in the struct being copied has its copy-constructor deleted.
FTR: to fix the code below you need to replace `return {ret}` with `return
{move(ret)}`.
# Steps to reproduce:
$ cat test.cpp
#include <memory>
#include <variant>
struct PacketErr {
std::unique_ptr<char> failed_devices;
};
std::variant<std::monostate, PacketErr> deserialize(){
PacketErr ret;
return {ret};
}
int main() {}
$ g++ test.cpp -std=c++17
test.cpp: In function ‘std::variant<std::monostate, PacketErr>
deserialize()’:
test.cpp:10:16: error: could not convert ‘{ret}’ from ‘<brace-enclosed
initializer list>’ to ‘std::variant<std::monostate, PacketErr>’
return {ret};
# Expected
GCC should mention that a copy is not possible since there's a copy-constructor
deleted.
# Actual
GCC basically says there's some error at the line — go figure what problem is
it.