Skip to content

Clang-format might cause compilation errors if a local library header is included with angle brackets #58300

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

Closed
doruktiktiklar opened this issue Oct 11, 2022 · 3 comments

Comments

@doruktiktiklar
Copy link

doruktiktiklar commented Oct 11, 2022

The code excerpt below compiles. But if I run clang-format on it, clang-format reorders these include definitions, causing some compilation errors. These compilation errors happen because glad.h redefines some macros

#include <glad/glad.h>
#include <GLFW/glfw3.h>

If I instead write it like below, the code compiles properly because clang-format does not reorder in this case.

#include "glad/glad.h"
#include <GLFW/glfw3.h>

This issue is somewhat related to the issue #53013

@llvmbot
Copy link
Member

llvmbot commented Oct 11, 2022

@llvm/issue-subscribers-clang-format

@dwblaikie
Copy link
Collaborator

I assume clang-format assumes headers are safely re-orderable. If you have headers that can't be reordered, I guess you have to turn off clang-format's include sorting.

@doruktiktiklar
Copy link
Author

Yes there is a --sort-includes flag and there is a SortIncludes flag in clang format style options as well. https://clang.llvm.org/docs/ClangFormatStyleOptions.html . As such, this is not an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants