Hello. -Wpadded warns about two issues, padding a struct field and padding at the end (i.e: the whole struct). See the example: ------------------- struct Bidule { char b; int a; char c; }; ---> test.cpp:4:6: warning: padding struct 'Bidule' with 3 bytes to align 'a' [-Wpadded] int a; ^ test.cpp:1:8: warning: padding size of 'Bidule' with 3 bytes to alignment boundary [-Wpadded] struct Bidule -------------------------- Usually padding in the middle is a bad thing because the struct can be "easily" organized differently to reduce the memory footprint. On the other hand, padding at the end of a structure is common and there is usually no trivial fix. As an example, I ran -Wpadded on a large code base, I found 3 padding of field which I fixed, and more than one thousand warning messages about padding of struct for which I cannot do something without complex code refactoring. It may be possible to split -Wpadding in two options, one which warns about padding fields (which I found really useful 100% of the time) and the other which warns about padding the whole struct, which IMHO only need to be activated when needed. Thank you.
+1 for -Wtail-padding
+1
-Wpadded-element and -Wpadded-structure sound good to me as proposed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52981 btw I don't any warnings, is this a bug? https://godbolt.org/z/oeL7-k
Or -Wpadded-field. Though this is an important point: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52981#c5
I made a point like this in the gcc bug, as linked above, but in light of new attributes, I think there are more considerations. Users usually do not care about answering "Is there padding in the middle of the structure", but "Can I rearrange my data members to save space?". Something like -Wwasted-space might be a good name for such a warning. It might further be worth giving this option two warning levels. The highest level would warn for all cases where rearranging can reduce size, and the lowest level would warn for all cases where rearranging only the private data members can reduce size. This is a potentially important point because rearranging public / protected data members can affect the API of your type by changing how it interacts with structured bindings, and, if it is also an aggregate, aggregate construction. The second thing the user might wonder is "Do I have padding that I cannot resolve by rearranging". This warning can alert the user that a small change in the size of their data types (or possibly moving data into different structures) could have a greater-than-expected size savings. This is more like the current -Wpadded. The important new consideration that has the potential for a third warning option is the handling of empty types. It could be useful to have a warning that alerts the user that marking a data member with [[no_unique_address]] would reduce the size of their structure. A potential name for this is -Wempty-data-member-wastes-space or -Wmissing-no-unique-address.