Header Forward Declaration

10 views
Skip to first unread message

Christopher Staite

unread,
Apr 21, 2026, 3:53:50 AM (9 days ago) Apr 21
to bu...@chromium.org
Hi All,

Victor Vianna and myself have been having a discussion about when it’s most appropriate to include headers for a type.

The discussion is mostly centred around whether it is required to include the header for a type that you pass or receive by value.  For reference this came up in https://crrev.com/c/7767457.

The conclusion is that you should include the headers for all types passed by reference to a function.

Currently this is not part of the advice in https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-dos-and-donts.md#minimize-code-in-headers

As the last editor of this I reached out to Erik who is currently on sabbatical and suggested I contact this mailing list to continue the discussion as to whether the advice on the above page should be extended to assist in these matters in the future.

Thanks, Chris.

Greg Thompson

unread,
Apr 21, 2026, 4:29:38 AM (9 days ago) Apr 21
to Christopher Staite, bu...@chromium.org
The Chromium style guide addresses this here: "You can and should use forward declarations for most types passed or returned by value, reference, or pointer, or types stored as pointer members or in most STL containers. However, if it would otherwise make sense to use a type as a member by-value, don't convert it to a pointer just to be able to forward-declare the type." Is there a new motivation to deviate from that?

--
You received this message because you are subscribed to the Google Groups "build" group.
To unsubscribe from this group and stop receiving emails from it, send an email to build+un...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/build/A0E031F4-A1B3-494D-869C-AC9E0050B6F6%40menlosecurity.com.

Christopher Staite

unread,
Apr 21, 2026, 4:34:11 AM (9 days ago) Apr 21
to Greg Thompson, bu...@chromium.org
Oh, excellent.  Thank you for the reference.  It now makes sense why those aren’t called out in the do’s and don’ts as they are specifically defined in the place that references it.

Thanks, Chris.
Reply all
Reply to author
Forward
0 new messages