<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56382>56382</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-format breaks with structs inside a scope
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-format
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          philnik777
      </td>
    </tr>
</table>

<pre>
    clang-format produces
```
bool test() {
  {{int comp_count = 0;
  auto comp = [&](int i) {
    ++comp_count;
    return i == 0;
  };
}
}

{
  struct S {};
}

return true;
}
```
If I remove the `{ struct S {}; }` it looks fine:
```
bool test() {
  {
    {
      int comp_count = 0;
      auto comp      = [&](int i) {
        ++comp_count;
        return i == 0;
      };
    }
  }

  return true;
}
```

The `.clang-format` is:
```
BasedOnStyle: LLVM

AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: Consecutive
AlignEscapedNewlines: Right
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortLambdasOnASingleLine: All
AttributeMacros: ['_LIBCPP_HIDE_FROM_ABI',
                  '_LIBCPP_CONSTEXPR',
                  '_LIBCPP_CONSTEXPR_AFTER_CXX11',
                  '_LIBCPP_CONSTEXPR_AFTER_CXX14',
                  '_LIBCPP_CONSTEXPR_AFTER_CXX17',
                  '_LIBCPP_CONSTEXPR_AFTER_CXX20',
                  '_LIBCPP_ALIGNOF',
                  '_ALIGNAS_TYPE',
                  '_ALIGNAS',
                  '_LIBCPP_NORETURN',
                  '_LIBCPP_ALWAYS_INLINE',
                  '_LIBCPP_DISABLE_EXTENTSION_WARNING',
                  '_LIBCPP_HIDDEN',
                  '_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS',
                  '_LIBCPP_FUNC_VIS',
                  '_LIBCPP_TYPE_VIS',
                  '_LIBCPP_TEMPLATE_VIS',
                  '_LIBCPP_TEMPLATE_DATA_VIS',
                  '_LIBCPP_EXPORTED_FROM_ABI',
                  '_LIBCPP_OVERRIDABLE_FUNC_VIS',
                  '_LIBCPP_EXCEPTION_ABI',
                  '_LIBCPP_ENUM_VIS',
                  '_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS',
                  '_LIBCPP_INTERNAL_LINKAGE',
                  '_LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION',
                  '_LIBCPP_HIDE_FROM_ABI_AFTER_V1',
                  '_LIBCPP_INLINE_VISIBILITY',
                  '_LIBCPP_CONSTEVAL',
                  '_LIBCPP_NOALIAS',
                  '_LIBCPP_USING_IF_EXISTS',
                  '_LIBCPP_DEPRECATED',
                  '_LIBCPP_DEPRECATED_IN_CXX11',
                  '_LIBCPP_DEPRECATED_IN_CXX14',
                  '_LIBCPP_DEPRECATED_IN_CXX17',
                  '_LIBCPP_DEPRECATED_IN_CXX20',
                  '_LIBCPP_NODISCARD',
                  '_LIBCPP_NODISCARD_EXT',
                  '_LIBCPP_NO_DESTROY',
                  '_LIBCPP_WEAK',
                  '_LIBCPP_CONSTINIT',
                  '_LIBCPP_FALLTHROUGH',
                  '_LIBCPP_STANDALONE_DEBUG',
                  '_LIBCPP_NO_UNIQUE_ADDRESS',
                 ]
BinPackArguments: false
BinPackParameters: false
BreakBeforeConceptDeclarations: true
BreakInheritanceList: BeforeColon
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
IndentWrappedFunctionNames: false
IndentRequires: true
InsertTrailingCommas: Wrapped
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PackConstructorInitializers: NextLine

PenaltyIndentedWhitespace: 61

Language: Cpp
Standard: c++20
SpacesInAngles: Leave

AlwaysBreakTemplateDeclarations: true
PointerAlignment: Left


# Disable formatting options which may break tests.
SortIncludes: false
ReflowComments: false

# libc++'s preferred indentions of preprocessor statements.
IndentPPDirectives: AfterHash

# libc++ has some long names so we need more than the 80 column limit imposed by LLVM style, for sensible formatting
ColumnLimit: 120
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylWEtzozgQ_jX2RbUpGyfx5OADNjhRDQEv4CRzcskgbG0AsUIkk_312xJ-YCeTwIwrRZD664e6W6Jbax6_TaKU5Ju_Ei4yIlEheFxFtOwNrN7A7F0Pdn96uOY8RZKWsmd86xk3qDee1gSkX8dTlksU8axYRbyC197IQoPe6AAileSarim9q2nPuO5dWSBNMbIzkSDUAMT0KLAhCiFBZSVyxJSsc0W9sXUYqfezl93wAC-lqCKJgnoVH7Hq504jgOkHkFNX4QRhMDHjLxTJLUWKMJ5-oEnbej1ATKKU8-cSJSwH8ebvBODouOYAoS_Con7H0Ohfu_h8GaOv4lTbap3MHDzaeN1PdIlA_Qxr3180k1y7u_yVj6ekpLGXB_ItVXFAjvNw35RopmyTm4mkwitoPhUkeqZSATWhgZnxvKRRJdkLNcsSJjKaS6UWNSgf46dMzhlN40_QdhmRgsYufU0hYTTQZ5utbEDAPkHyWsiJ1YJILhrAUBAGUjYznh1s1D7eQVL-Cg9TbCpN9nKX_pROnacfABdEkIyCqtJLLAqeB32M55-yBVsu5LzKI4UEDWYA9qT0M7RDsnVM3mMBsYNKKdi6kvSeRILrVemcHq8cPJ0tFqs7bNmrue_dr8wphvmeMTvN3eOvwTXz3CC0nxZ-d46VOQ9tfzV7ehoO_4j78o-4x3_CbQxac5sOvnW9-dd4DTSDVfhjYbdGtzbD9Xw7XPpuB7sfzR_BCrsOdlvYs-OycGBOHXtlP4W2GwbYc1ePpu9i97a1CEhIy25v570d3nnWKrTvF44Z2isM__EMh2B5EJpuiM1QWfGA2_tqvnRnnRhUyLox7K39LSbLDM1OnJC8nh_aVvd97j3Yvo8tHdPObrGfZvZCe7-LSttd3ndUA7vSPbqnczSwqwSYDozd7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