Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format breaks with structs inside a scope #56382

Closed
philnik777 opened this issue Jul 5, 2022 · 3 comments
Closed

clang-format breaks with structs inside a scope #56382

philnik777 opened this issue Jul 5, 2022 · 3 comments
Labels
clang-format duplicate Resolved as duplicate

Comments

@philnik777
Copy link
Contributor

philnik777 commented Jul 5, 2022

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
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 5, 2022

@llvm/issue-subscribers-clang-format

@eoan-ermine
Copy link
Contributor

eoan-ermine commented Jul 16, 2022

Smaller producer (config.txt):

void f() {
  {
    {
      int x;
    }
  }
  { }
}

That formats as

void f() { {{int x; }
}
{}
}

@rymiel
Copy link
Member

rymiel commented Jan 1, 2023

Duplicate of #33891, given the reduction

@rymiel rymiel closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2023
@rymiel rymiel added the duplicate Resolved as duplicate label Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants