clang-format: Set PackConstructorInitializers: CurrentLine #33912

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2511-clang-format-PackConstructorInitializers changing 2 files +4 −2
  1. maflcko commented at 10:10 am on November 20, 2025: member

    Now that the minimum supported clang version is larger than 14, the PackConstructorInitializers setting can be set to CurrentLine in the clang-format file. (This option was added in clang 14. Ref: https://releases.llvm.org/17.0.1/tools/clang/docs/ClangFormatStyleOptions.html#packconstructorinitializers)

    The CurrentLine option will either put all constructor initializers on the current line if they fit. Otherwise, it will put each one on its own line.

    The CurrentLine option is desirable over the current BinPack option, because:

    • It is what the majority of the codebase is currently using.
    • It makes it easier to skim the lines to ensure all fields are properly initialized, without having to parse bin-packed constructor initializers, possibly with nested initializer lists, function calls, or ternary operators.
    • It makes diffs smaller when an initializer is added or removed, because only a single line is touched. Otherwise, the whole bin-packed block could re-flow, making the diff harder to parse.

    Note: The previous BinPack option allows any formatting, due to the current ColumnLimit: 0. I presume developers manually formatted most constructor initializers to be on separate lines? With the new CurrentLine setting, one has to only put the first initializer on a separate line, and clang-format will take care of the rest.

    For example:

    0echo 'A::A(O o)
    1: m_first{o.a, o.b},
    2  m_second{fun(o)}, m_third{o.c?o.d:o.e} {}' | clang-format --style=file:./src/.clang-format
    

    Will put each on a separate line. Previously, it was left as-is.

  2. clang-format: Set PackConstructorInitializers: CurrentLine fad0c76d0a
  3. DrahtBot commented at 10:10 am on November 20, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33912.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK l0rinc, TheCharlatan, hebasto

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. in src/.clang-format:149 in fad0c76d0a
    145@@ -146,7 +146,7 @@ ObjCBlockIndentWidth: 2
    146 ObjCBreakBeforeNestedBlockParam: true
    147 ObjCSpaceAfterProperty: false
    148 ObjCSpaceBeforeProtocolList: true
    149-PackConstructorInitializers: BinPack
    150+PackConstructorInitializers: CurrentLine
    


    l0rinc commented at 10:47 am on November 20, 2025:

    Now that the minimum supported clang version is 17, the PackConstructorInitializers setting can be set to CurrentLine in the clang-format file.

    Nit: CurrentLine was already available in 16

    The new addition in 17 is NextLineOnly:


    maflcko commented at 11:00 am on November 20, 2025:

    Thx, nice find. NextLineOnly is actually even closer to what this project is using. I’ve switched to that

    Edit: Nvm, it is not closer to what this project is using. Reverted to the old commit :sweat_smile:

    Edit: Resolving thread for now. Let me know if there is something left to change or discuss.


    l0rinc commented at 11:08 am on November 20, 2025:
    I’m fine with both, just want, agree that BinPack is not the best one - can you please update the PR description to reflect that the current one wasn’t necessarily motivated by the 16 -> 17 upgrade.

    maflcko commented at 11:51 am on November 20, 2025:
    thx, reworded the pull description, happy to adjust it more, if you have suggestions.
  5. l0rinc approved
  6. l0rinc commented at 10:48 am on November 20, 2025: contributor

    ACK fad0c76d0a109ab7b063f0d405588cf1e6c15e4d

    I agree that this is our best option now, mostly because it will minimize diffs without blowing up line-count for trivial ones

  7. maflcko renamed this:
    clang-format: Set PackConstructorInitializers: CurrentLine
    clang-format: Set PackConstructorInitializers: NextLineOnly
    on Nov 20, 2025
  8. maflcko force-pushed on Nov 20, 2025
  9. maflcko force-pushed on Nov 20, 2025
  10. DrahtBot added the label CI failed on Nov 20, 2025
  11. maflcko renamed this:
    clang-format: Set PackConstructorInitializers: NextLineOnly
    clang-format: Set PackConstructorInitializers: CurrentLine
    on Nov 20, 2025
  12. DrahtBot removed the label CI failed on Nov 20, 2025
  13. TheCharlatan approved
  14. TheCharlatan commented at 9:19 pm on November 20, 2025: contributor
    ACK fad0c76d0a109ab7b063f0d405588cf1e6c15e4d
  15. hebasto approved
  16. hebasto commented at 9:46 pm on November 20, 2025: member
    ACK fad0c76d0a109ab7b063f0d405588cf1e6c15e4d.
  17. hebasto merged this on Nov 20, 2025
  18. hebasto closed this on Nov 20, 2025

  19. maflcko deleted the branch on Nov 20, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-01 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me