- Use
IWYU pragma: keep
to force IWYU to keep any#include
directive that would be discarded under its normal policies. - Use
IWYU pragma: always_keep
to force IWYU to keep a header in all includers, whether they contribute any used symbols or not. - Use
IWYU pragma: export
to tell IWYU that one header serves as the provider for all symbols in another, included header (e.g. facade headers). UseIWYU pragma: begin_exports/end_exports
for a whole group of included headers. - Use
IWYU pragma: no_include
to tell IWYU that the file in which the pragma is defined should never#include
a specific header (the header may already be included via some other#include
.) - Use
IWYU pragma: no_forward_declare
to tell IWYU that the file in which the pragma is defined should never forward-declare a specific symbol (a forward declaration may already be available via some other#include
.) - Use
IWYU pragma: private
to tell IWYU that the header in which the pragma is defined is private, and should not be included directly. - Use
IWYU pragma: private, include "public.h"
to tell IWYU that the header in which the pragma is defined is private, andpublic.h
should always be included instead. - Use
IWYU pragma: friend ".*favorites.*"
to overrideIWYU pragma: private
selectively, so that a set of files identified by a regex can include the file even if it's private.
The pragmas come in three different classes;
- Ones that apply to a single
#include
directive (keep
,export
) - Ones that apply to a file being included (
private
,friend
,always_keep
) - Ones that apply to a file including other headers (
no_include
,no_forward_declare
)
Some files are both included and include others, so it can make sense to mix and match.
https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md