[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 19 17:47:32 PDT 2023


================
@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
   SmallVector<StackEntry, 8> LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-    // Get next non-comment token.
-    FormatToken *NextTok;
-    do {
-      NextTok = Tokens->getNextToken();
-    } while (NextTok->is(tok::comment));
+    // Get next non-comment, non-preprocessor token.
+    FormatToken *NextTok = Tokens->getNextToken();
+    while (NextTok->is(tok::comment) ||
+           (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+      while (NextTok->is(tok::comment))
+        NextTok = Tokens->getNextToken();
+      while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+        ScopedMacroState MacroState(*Line, Tokens, NextTok);
+        do {
+          NextTok = Tokens->getNextToken();
+        } while (NextTok->isNot(tok::eof));
+      }
+    }
----------------
owenca wrote:

Can you give a valid C/C++ example? As far as I know, you can't have `#` after `{`.

https://github.com/llvm/llvm-project/pull/69473


More information about the cfe-commits mailing list