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

Mark Zeren via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 15 03:45:40 PDT 2017


mzeren-vmw added inline comments.


================
Comment at: unittests/Format/FormatTest.cpp:2281
 
 TEST_F(FormatTest, LayoutMacroDefinitionsStatementsSpanningBlocks) {
   verifyFormat("#define A \\\n"
----------------
mzeren-vmw wrote:
> Experimenting with the patch locally I found that comment indentation is broken in some cases. Please add tests that cover comments. For example:
> 
> comment indented at code level as expected:
>   void f() {
>   #if 0
>     // Comment
>     code();
>   #  define FOO 0
>   #endif
>   }
> comment not indented at code level when there's a guard:
>   #ifndef _SOMEFILE_H
>   #define _SOMEFILE_H
>   void f() {
>   #if 0
>   // Comment
>     code();
>   #  define FOO 0
>   #endif
>   }
>   #endif
> 
> The `#define FOO 0` is required to trigger this behavior.
Erik spent some time investigating issues with comment indentation. A couple of insights so far:

a) We need tests for wrapped macros (with trailing \ continuations). These need to include embedded comments.

b) It would be most natural to align comments with the following non-comment line. So a comment may be indented at "preprocessor level" or "code level". If indented at preprocessor level we have to handle the extra space introduced by the leading hash. This may require an extra bit per line to indicate whether the "aligned-to" line is preprocessor or code.


https://reviews.llvm.org/D35955





More information about the cfe-commits mailing list