[PATCH] D35955: clang-format: Add preprocessor directive indentation

Erik Uhlmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 15 14:32:50 PDT 2017


euhlmann added inline comments.


================
Comment at: unittests/Format/FormatTest.cpp:2405-2408
+  // Defect: We currently do not deal with cases where legitimate lines may be
+  // outside an include guard. Examples are #pragma once and
+  // #pragma GCC diagnostic, or anything else that does not change the meaning
+  // of the file if it's included multiple times.
----------------
mzeren-vmw wrote:
> We need to handle comments (like copyrights) before the include guard. There is an analogous problem with trailing blank lines, or trailing comments.
> 
> I think we need a small state machine: Init, Start, Open, Closed, NotGuard (terminal). `FoundIncludeGuardStart` should change from a bool to an enum to track this state. `PPMaybeIncludeGuard` can then drop it's "mabye". Whether or not it is null depends directly on the state. It does not determine state itself. While parsing, each line updates the state. If we get to `eof` in the Closed state then we have detected an include guard. ... Or similar logic....
> 
> Note that support for comments before the guard opens the door to support for #pragma once. It is tempting to add that, but that is a slippery slope. I would recommend leaving that as a defect that can be addressed later.
@djasper @klimek
Do you have any comments on this? I've begun to implement an enum/state machine but I'd like to know if you'd like me to implement a different way.


https://reviews.llvm.org/D35955





More information about the cfe-commits mailing list