Clang plugin no longer warns about complex constructors/destructors for aggregate types

42 views
Skip to first unread message

Daniel Cheng

unread,
Jul 22, 2026, 11:41:29 PM (13 days ago) Jul 22
to cxx
If your type (and all its transitive base classes) meets the rules for a C++ aggregate (no virtual functions, no protected/private fields, no user-declared/inherited constructors), the clang plugin will no longer warn about complex constructors and destructors [1].

This allows you to use designated initializers or ensure your type is trivially copyable for shared memory.

Please keep in mind the Google C++ style guidance for structs:
Use a struct only for passive objects that carry data; everything else is a class. [...] If more functionality or invariants are required, or struct has wide visibility and expected to evolve, then a class is more appropriate. If in doubt, make it a class.

Finally, if your type does not need to be an aggregate, it's still better to define your constructors/destructors out of line [2].

Daniel

[1] An astute reader might notice that having a user-declared destructor does not disqualify a type from being an aggregate; however, a user-declared destructor prevents the compiler from synthesizing an implicitly-declared move constructor, which results in worse outcomes overall.
[2] There is a modest increase in binary size with implicitly-defined constructors/destructors; https://crrev.com/c/7763597 contains numbers from converting 61 candidate types to use designated initializers.

Arthur Sonzogni

unread,
Jul 23, 2026, 5:04:09 AM (13 days ago) Jul 23
to Daniel Cheng, cxx
Congrats on landing this, Daniel! Just wanted to say this is greatly appreciated. Unlocking more designated initializers is a huge quality-of-life improvement. Thanks for driving this!
Arthur @arthursonzogni


--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAF3XrKpWJnTR_mScYmyG0u%3DS%3D%3DbFj6BqmZS-oumyLotOtiY-ZQ%40mail.gmail.com.

K. Moon

unread,
Jul 23, 2026, 1:18:52 PM (13 days ago) Jul 23
to Arthur Sonzogni, Daniel Cheng, cxx
+100, wanted this since C++20 was allowed.

Reply all
Reply to author
Forward
0 new messages