Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#include style #742

Open
PengZheng opened this issue Apr 11, 2024 · 0 comments
Open

#include style #742

PengZheng opened this issue Apr 11, 2024 · 0 comments
Labels
project/style Project wide coding guide style

Comments

@PengZheng
Copy link
Contributor

PengZheng commented Apr 11, 2024

I just came across LLVM's coding standard during my LLVM adventure, and found the paragraph about #include style inspiring:

We prefer these #includes to be listed in this

  1. Main Module
  2. Local/Private Headers
  3. LLVM project/subproject headers (clang/..., lldb/..., llvm/..., etc)
  4. System #includes

The Main Module Header file applies to .cpp files which implement an interface defined by a .h file. This #include should always be included first regardless of where it lives on the file system. By including a header file first in the .cpp files that implement the interfaces, we ensure that the header does not have any hidden dependencies which are not explicitly #included in the header, but should be. It is also a form of documentation in the .cpp file to indicate where the interfaces it implements are defined.

LLVM project and subproject headers should be grouped from most specific to least specific, for the same reasons described above.

For more, check this.
How about adding it to our coding conventions and .clang-format?

@PengZheng PengZheng added the project/style Project wide coding guide style label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project/style Project wide coding guide style
Projects
None yet
Development

No branches or pull requests

1 participant