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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
I think the -Wpacked-not-aligned warning would work well here.  There was a
request some time ago to issue a warning for things like:

  struct __attribute__ ((packed)) S {
    std::mutex mtx;
    ...
  };

Decorating std::mutex (and other C++ standard library classes that need to be
aligned) with attribute warn_if_not_aligned would trigger the warning.

Alternatively, adding a new #pragma warn_if_not_aligned to effectively annotate
all type definitions in a header with the attribute would avoid having to
modify every class in the C++ standard library to add the attribute explicitly.

Another alternative would be to implicitly reset the #pragma pack on "entry" to
every C++ standard header (or even every header), and restore it on "exit."

Reply via email to