[PATCH] D35485: [clang-format] Fix comment levels between '}' and PPDirective

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 18 02:58:47 PDT 2017


krasimir added inline comments.


================
Comment at: lib/Format/UnwrappedLineParser.cpp:489
 
-  nextToken(); // Munch the closing brace.
+  nextToken(InitialLevel); // Munch the closing brace.
 
----------------
djasper wrote:
> What happens if you instead change the Line->Level = InitialLevel; statement from below to before this line? That seems like the more intuitively correct fix.
This doesn't work since comments before the right brace haven't been emitted yet and would get the wrong level.


================
Comment at: unittests/Format/FormatTestComments.cpp:848
+            "}",
+            format("int f(int i) {\n"
+                   "  if (true) {\n"
----------------
djasper wrote:
> Generally, mess up the code in some way to ensure that it is actually being formatted.
Messing up doesn't work in this case, because we rely on the original columns of the comment and the previous line. That's why I added a bunch of tests.


https://reviews.llvm.org/D35485





More information about the cfe-commits mailing list