-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Clang-format SortIncludes does not allow main headers in <> instead of "" #63619
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
Labels
Comments
@llvm/issue-subscribers-clang-format |
j-jorge
added a commit
to j-jorge/llvm-project
that referenced
this issue
Jan 19, 2024
j-jorge
added a commit
to j-jorge/llvm-project
that referenced
this issue
Jan 21, 2024
j-jorge
added a commit
to j-jorge/llvm-project
that referenced
this issue
Jan 22, 2024
owenca
pushed a commit
that referenced
this issue
Feb 6, 2024
Resolves #27008, #39735, #53013, #63619. Hello, this PR adds the MainIncludeChar option to clang-format, allowing to select which include syntax must be considered when searching for the main header: quotes (`#include "foo.hpp"`, the default), brackets (`#include <foo.hpp>`), or both. The lack of support for brackets has been reported many times, see the linked issues, so I am pretty sure there is a need for it :) A short note about why I did not implement a regex approach as discussed in #53013: while a regex would have allowed many extra ways to describe the main header, the bug descriptions listed above suggest a very simple need: support brackets for the main header. This PR answers this needs in a quite simple way, with a very simple style option. IMHO the feature space covered by the regex (again, for which there is no demand :)) can be implemented latter, in addition to the proposed option. The PR also includes tests for the option with and without grouped includes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clang-format has advanced detection of the "main header" of a C++ file to keep it as the first include. However, this only works if the main header file is referenced using double quotes (
"myproject/MyClass.h"
), not if the main header is referenced using angle brackets (<myproject/MyClass.h>
). This is invalid because there is no strict rule to put main header includes into double quotes.Root cause
Clang-format has a hard-coded check that the main header file should be included with double quotes.
Reproduction scenario
Project layout:
.clang-format file:
MyClass.cc:
Clang-format will reformat this to:
because it doesn't recognize
<myproject/MyClass.h>
as the main header reference.Workaround: change MyClass.cc to:
The text was updated successfully, but these errors were encountered: