Date: Tue, 11 Jul 2023 13:17:38 +0300
Thanks for the prompt reply!
On Tue, 11 Jul 2023 at 12:53, Jonathan Wakely <cxx_at_[hidden]> wrote:
>
> Why should Thingy3() = default; give you that behaviour? It's still
> trivial and it is noexcept. Why should it prevent Thingy3() from zeroing
> the members?
>
The phrasing of this question assumes zeroing the members is some natural
default and deviating from it requires justification. I believe in C++ it's
the other way around: you don't pay for what you don't use, so me & quite a
few people I talked to would expect `= default` to consistently not
initialize the members, in all initialization forms.
One could just as well ask: "Why should `=default` prevent `Thingy3 t3;`
from zeroing the members?" - except that it does, and it is very natural
to expect consistent impact of `=default`.
>
> If defining it as defaulted behaved how you want, then there would be no
> way to say "it's default constructible, but I still want it to be trivial".
> If you do want it to be non-trivial, you can already do that, as you did
> for Thingy2.
>
Not sure I understand this, and if I do - not sure I agree. If you want to
say "it's default constructible, but the ctor zeros members" (is that what
you mean by 'trivial'?) then there certainly is a way to express it: just
write a default ctor that zeros the members.
On Tue, 11 Jul 2023 at 12:53, Jonathan Wakely <cxx_at_[hidden]> wrote:
>
> Why should Thingy3() = default; give you that behaviour? It's still
> trivial and it is noexcept. Why should it prevent Thingy3() from zeroing
> the members?
>
The phrasing of this question assumes zeroing the members is some natural
default and deviating from it requires justification. I believe in C++ it's
the other way around: you don't pay for what you don't use, so me & quite a
few people I talked to would expect `= default` to consistently not
initialize the members, in all initialization forms.
One could just as well ask: "Why should `=default` prevent `Thingy3 t3;`
from zeroing the members?" - except that it does, and it is very natural
to expect consistent impact of `=default`.
>
> If defining it as defaulted behaved how you want, then there would be no
> way to say "it's default constructible, but I still want it to be trivial".
> If you do want it to be non-trivial, you can already do that, as you did
> for Thingy2.
>
Not sure I understand this, and if I do - not sure I agree. If you want to
say "it's default constructible, but the ctor zeros members" (is that what
you mean by 'trivial'?) then there certainly is a way to express it: just
write a default ctor that zeros the members.
Received on 2023-07-11 10:17:51