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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Any default member initializer has the same problem, not just a
braced-init-list, i.e. all of these cause an error:

class DoesntCompile
{
    std::unique_ptr<S> s{};
    std::unique_ptr<S> s = std::unique_ptr<S>();
    std::unique_ptr<S> t = nullptr;
};


[class.mem]p9 says a default member initializer should not cause the
constructor to be defined:

A brace-or-equal-initializer for a non-static
data member specifies a default member initializer for the member, and shall
not directly or indirectly cause
the implicit definition of a defaulted default constructor for the enclosing
class or the exception specification
of that constructor.

[class.ctor]p7 says the constructor is defined when odr-used:

A default constructor that is defaulted and not defined as deleted is
implicitly defined when it is odr-used (6.2)
to create an object of its class type (6.6.2), when it is needed for constant
evaluation (8.6), or when it is
explicitly defaulted after its first declaration.

So we shouldn't need the DoesntCompile constructor here, and so shouldn't need
to instantiate the destructor of std::unique_ptr<S>.

Reply via email to