google / styleguide

Style guides for Google-originated open-source projects

Home Page:https://google.github.io/styleguide/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contradiction between C++ styleguide and cpplint regarding transitive includes

geoffviola opened this issue · comments

This issue comes from cpplint#218

The Google C++ Style Guide states that

Do not rely on transitive inclusions. This allows people to remove no-longer-needed #include statements from their headers without breaking clients. This also applies to related headers - foo.cc should include bar.h if it uses a symbol from it even if foo.h includes bar.h.

The second part about including the direct dependencies in the source file regardless of the corresponding header, contradicts with cpplint. When cpplint is run on a source file, it counts the includes in its corresponding header file as included.

The policy is that if you #include something in foo.h you don't need to
include it again in foo.cc. Here, we will look at possible includes.

Which rule should be followed?