[clang] [clang-format] Correctly annotate designated initializer with PP if (PR #65409)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 6 23:00:57 PDT 2023


================
@@ -626,6 +626,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
     case tok::kw_switch:
     case tok::kw_try:
     case tok::kw___try:
+      if (PrevTok->is(tok::hash))
+        break;
----------------
owenca wrote:

This should be applied to `kw_if` only, right? So something like the following instead?
```
    case tok::identifier:
      if (Tok->isNot(TT_StatementMacro))
        break;
      [[fallthrough]];
    case tok::kw_if:
      if (PrevTok->is(tok::hash))
        break;
      [[fallthrough]];
    case tok::at:
    case tok::semi:
    case tok::kw_while:
    case tok::kw_for:
    case tok::kw_switch:
    case tok::kw_try:
    case tok::kw___try:
      if (!LBraceStack.empty() && LBraceStack.back().Tok->is(BK_Unknown))
        LBraceStack.back().Tok->setBlockKind(BK_Block);
      break;
```

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


More information about the cfe-commits mailing list