Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

How can I make it such that clang-format always breaks all functions if they don't fit…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Qwenqwen-max-2025-01-25’s answer.
  1. User

    How can I make it such that clang-format always breaks all functions if they don't fit on a single line ex. Private::validateResult( CreateDebugUtilsMessengerEXT(\n, here clang-format only breaks after the last function, I would like it to either have everything on one line or break after each (, no putting multiple ( and ) on a single line.

  2. Claude Assistant

    You can achieve this behavior by configuring clang-format with these key settings:

    # In your .clang-format file
    BinPackParameters: false
    BinPackArguments: false
    AllowAllParametersOfDeclarationOnNextLine: false
    AllowAllArgumentsOnNextLine: false
    

    The most important setting for your specific case is BinPackParameters: false and BinPackArguments: false. These prevent clang-format from packing multiple parameters or arguments on the same line.

    However, for nested function calls like your example, you might also want to add:

    BreakBeforeBinaryOperators: None
    AlwaysBreakAfterReturnType: None
    AlwaysBreakAfterDefinitionReturnType: None
    

    If you want even more aggressive breaking for complex expressions, you can also try:

    BreakBeforeTernaryOperators: true
    BreakConstructorInitializers: BeforeColon
    BreakInheritanceList: BeforeColon
    

    For your specific example with nested function calls, the key settings are the first four I mentioned. This should give you either everything on one line (if it fits) or proper breaking after each opening parenthesis when the line becomes too long.

    You can test these settings by creating a .clang-format file in your project root with these options, or by using the -style flag with clang-format to test the configuration before committing to it.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.