Date: Mon, 4 Dec 2023 03:14:27 +0100
public->private solved it for non-empty classes. Probably standard-layout vs. not.
https://godbolt.org/z/3a8oKxP9x
Is an default copy assignment (instead of a memset) within the base class always safe(r)?
E.g. implementing Base_nonempty::clear() as { *this = Base_nonempty{}; }
And calling it for the derived class?
So would a default copy assignment leave the padding bits alone?
-----Ursprüngliche Nachricht-----
Von:Breno Guimarães via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Mo 04.12.2023 02:13
Betreff:Re: [std-proposals] std::sizeof_minus_trailing_padding
An:Std-Proposals <std-proposals_at_[hidden]>;
CC:Breno Guimarães <brenorg_at_[hidden]>;
I'm on my phone and Godbolt is awful here so I can't test, but the problem is likely that your class is POD.
As with everything in c++, terms and conditions may apply.
So if you make members private it will probably fix it, if I'm not mistaken.
Might want to checkout
https://stackoverflow.com/questions/25226347/gcc-clang-lay-out-fields-of-a-derived-struct-in-the-back-padding-of-base-struct/51334730#51334730
Em dom., 3 de dez. de 2023 19:57, Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> > escreveu:
Hi Breno,
I can see the padding of base classes being used (without attribute) only for empty base classes.
See
https://godbolt.org/z/bnnohMGTv
What am I missing?
Best,
Sebastian
-----Ursprüngliche Nachricht-----
Von:Breno Guimarães via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> >
Gesendet:So 03.12.2023 23:17
Betreff:Re: [std-proposals] std::sizeof_minus_trailing_padding
An:Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> >;
CC:Breno Guimarães <brenorg_at_[hidden] <mailto:brenorg_at_[hidden]> >;
Yeah, the link only talks about empty base class optimization, but that happens with non empty too. It should've been called "padding optimization" or something.
Just derive a class with trailing padding and add a member that can fit in the padding and the padding will be reused.
Em dom., 3 de dez. de 2023 18:48, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> > escreveu:
On Sun, Dec 3, 2023 at 7:20 PM Breno Guimarãeswrote:
>
> By the way, the no_unique_address annotation didn't bring the concept of overlapping objects. It already existed.
>
> https://en.cppreference.com/w/cpp/language/ebo
But people haven't been memcpy'ing and memset'ing empty base classes
for a few decades.
Bringing it in for types where people would have historically been
using 'memset' as a bulldozer for a few decades is a much bigger deal.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
-- Std-Proposals mailing list Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2023-12-04 02:14:29