[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

Noah Goldstein via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 1 11:36:31 PDT 2022


goldstein.w.n created this revision.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  I.e with:
  PPIndentWidth = 1
  IndentWidth = 4
  ```
  #ifdef foo
  #define bar() if (A) { B(); } C();
  #endif
  ```
  
  Assume ColumnLimit Here:    |
  
  IndentPPDirectives: None
  ```
  #ifdef foo
  #define bar()               \
      if (A) {                \
          B();                \
      }                       \
      C();                    \
  #endif
  ```
  
  As opposed to
  ```
  #ifdef foo
  #define bar()               \
    if (A) {                  \
     B();                     \
    }                         \
    C();
  #endif
  ```
  
  IndentPPDirectives: AfterHash
  ```
  #ifdef foo
  # define bar()              \
      if (A) {                \
          B();                \
      }                       \
      C();                    \
  #endif
  ```
  
  As opposed to
  ```
  #ifdef foo
  # define bar()              \
    if (A) {                  \
     B();                     \
    }                         \
    C();
  #endif
  ```
  
  IndentPPDirectives: BeforeHash
  ```
  #ifdef foo
   #define bar()              \
      if (A) {                \
          B();                \
      }                       \
      C();                    \
  #endif
  ```
  
  As opposed to
  ```
  #ifdef foo
   #define bar()              \
    if (A) {                  \
     B();                     \
    }                         \
    C();
  #endif
  ```


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137181

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -60,7 +60,7 @@
     // Update the indent level cache size so that we can rely on it
     // having the right size in adjustToUnmodifiedline.
     skipLine(Line, /*UnknownIndent=*/true);
-    if (Line.InPPDirective ||
+    if ((Line.InPPDirective && !Line.InMacroBody) ||
         (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash &&
          Line.Type == LT_CommentAbovePPDirective)) {
       unsigned IndentWidth =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137181.472361.patch
Type: text/x-patch
Size: 644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221101/77fd27d1/attachment-0001.bin>


More information about the cfe-commits mailing list