https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84782

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Raphael Kubo da Costa from comment #5)
> Sorry if my comment was too coarse-grained. My hypothesis that this is a
> duplicate comes from playback_image_provider.ii looking like Chromium's
> playback_image_provider.cc, which was failing to build with GCC when a copy
> constructor was not defined inline (just like the union from bug 70431).

Not every example with a non-inline copy constructor is the same though.

> My reduced testcase from the original Chromium code (without templates)
> looks like this:
> 
> -----
> struct S1 {
>   S1& operator=(const S1&) = default;
>   S1& operator=(S1&&) = default;
> };
> 
> struct S2 {
>   S2() = default;
>   S2(const S2&);
>   S1 m;
> };
> 
> S2::S2(const S2&) = default;
> -----
> 
> x.cc:12:1: note: ‘S2::S2(const S2&)’ is implicitly deleted because the
> default definition would be ill-formed:
>  S2::S2(const S2&) = default;
>  ^~
> x.cc:12:1: error: use of deleted function ‘constexpr S1::S1(const S1&)’
> x.cc:1:8: note: ‘constexpr S1::S1(const S1&)’ is implicitly declared as
> deleted because ‘S1’ declares a move constructor or move assignment operator
>  struct S1 {
>         ^~
> 
> The error goes away if S2's copy constructor is declared inline.

Because that's what the C++ standard requires. A copy constructor that is
defined as defaulted outside the class body is ill-formed if it would be
implicitly deleted. If it's defaulted on its first declaration (i.e. inside the
class body) then it is defined as deleted.

Your example is not valid, and is rejected by GCC and Clang and EDG.

Reply via email to