clang-format: align brace-after-struct and *-class formatting #32813

pull l0rinc wants to merge 2 commits into bitcoin:master from l0rinc:l0rinc/clang-format changing 3 files +195 −21
  1. l0rinc commented at 3:40 pm on June 25, 2025: contributor

    Updates .clang-format file to reflect latest supported Clang-Format standards while preserving most of the existing formatting behavior, except for the very last commit which aligns AfterStruct brace placement with AfterClass for code formatting.

    The first commit reformats a file containing a C++ struct, the second one modifies the formatting and reformats the same file to show the difference.

  2. DrahtBot commented at 3:40 pm on June 25, 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/32813.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  3. in src/.clang-format:49 in a666d8ab6f outdated
    44 SpacesInCStyleCastParentheses: false
    45 SpacesInParentheses: false
    46-BreakBeforeConceptDeclarations: Always
    47-RequiresExpressionIndentation: OuterScope
    48-Standard: c++20
    49-UseTab:          Never
    


    maflcko commented at 3:49 pm on June 25, 2025:
    a666d8ab6f3c019a9f7e184beb9b90affbb8075c: not sure about removing the default values. I don’t think there is any harm in having them. In fact, we don’t want this to silently change from down under with the next clang update.

    l0rinc commented at 3:58 pm on June 25, 2025:
    What about the other default values, what if those change?

    maflcko commented at 4:17 pm on June 25, 2025:
    I’d say the others are probably edge cases to not matter much, but no strong opinion. Seems fine to add them as well to avoid silent changes. However, I don’t think the config is forward compatible, so it can probably only contain keys of the minimum required clang version.

    l0rinc commented at 9:53 pm on June 25, 2025:
    I’ve added all of them, this was the simplest change with fewest commits and explanations

    maflcko commented at 4:37 pm on June 26, 2025:

    Again, as said in my previous comment this doesn’t work, because older clang-formats will just error out:

    0$ clang-format-16 -i src/bench/prevector.cpp
    1/b-c/src/.clang-format:12:3: error: unknown key 'AlignFunctionPointers'
    2  AlignFunctionPointers: false
    3  ^~~~~~~~~~~~~~~~~~~~~
    4Error reading /b-c/src/.clang-format: Invalid argument
    

    l0rinc commented at 9:35 am on June 27, 2025:
    Thanks, managed to install an older version and redid the changes for maximal compatibility.
  4. in src/.clang-format:3 in 7dda3d2c0e outdated
    0@@ -1,26 +1,40 @@
    1 AccessModifierOffset: -4
    2-AlignAfterOpenBracket: true
    3+AlignAfterOpenBracket: Align
    


    maflcko commented at 3:52 pm on June 25, 2025:
    7dda3d2c0e65ac1fa08ac3b24a13f2005c6bef1a: not sure about changing the values. seems fine to just keep the old value, which will likely work forever in a backward compatible way

    l0rinc commented at 4:00 pm on June 25, 2025:
    Many of these keys aren’t even listed in the documentation and the IDE shows that many are invalid since it doesn’t match the allowed schema.
  5. maflcko commented at 3:53 pm on June 25, 2025: member
    last commit seems fine, but the others i am not sure. at a minimum you’ll have to drop the scripted diffs from executing, because they can’t be reproduced anyway with different clang-format versions
  6. DrahtBot added the label CI failed on Jun 25, 2025
  7. DrahtBot commented at 5:06 pm on June 25, 2025: contributor

    🚧 At least one of the CI tasks failed. Task lint: https://github.com/bitcoin/bitcoin/runs/44780552247 LLM reason (✨ experimental): The CI failure is caused by errors in the lint check, related to code style or formatting issues.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  8. l0rinc force-pushed on Jun 25, 2025
  9. l0rinc force-pushed on Jun 25, 2025
  10. DrahtBot removed the label CI failed on Jun 26, 2025
  11. clang-format: regenerate configs
    Regenerated `.clang-format` from current configs to replace deprecated keys with up-to-date equivalents.
    Also added all current formatter default values to guard against version differences.
    
    The configs were updated with the following command (using v16 for maximal compatibility):
       $(brew --prefix llvm@16)/bin/clang-format -dump-config -style=file:src/.clang-format
    
    The new config was tested with:
       $(brew --prefix llvm@16)/bin/clang-format -i src/deploymentinfo.h
    
    Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
    7c9b3e1eae
  12. clang-format: align `AfterStruct` with `AfterClass` in `BraceWrapping`
    The new config was tested with the same file as the previous commit to showcase the changes:
      $(brew --prefix llvm@16)/bin/clang-format -i src/deploymentinfo.h
    94364a7d54
  13. l0rinc force-pushed on Jun 27, 2025
  14. l0rinc marked this as ready for review on Jun 29, 2025
  15. l0rinc renamed this:
    clang-format: modernize and realign clang-format configuration
    clang-format: align brace-after-struct and *-class formatting
    on Jun 29, 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-07-07 21:13 UTC

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