clang-format: Set BraceWrapping:AfterControlStatement:MultiLine #23216

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2110-srcFormat changing 1 files +1 −0
  1. MarcoFalke commented at 10:15 AM on October 7, 2021: member

    Currently there is no visual break between the condition of a control statement and the body. For example:

    if (IsThisTrue() ||
        IsThatTrue()) {
        DoThis;
        DoThat;
    }
    

    Fix this by allowing the brace to be on a new line.

    Currently clang-format won't re-format existing code, presumably due to the line-limit setting. However, the new line can be manually inserted and clang-format will no longer remove it with this new setting. So this can be tested by "injecting" a newline after a multi line control statement and calling clang-format-diff, as explained in the dev notes.

    Example location to test:

    diff --git a/src/net_processing.cpp b/src/net_processing.cpp
    index 66b99aa2bb..f7dee82335 100644
    --- a/src/net_processing.cpp
    +++ b/src/net_processing.cpp
    @@ -4313,7 +4313,8 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
     void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now)
     {
         if (m_connman.ShouldRunInactivityChecks(node_to) && peer.m_ping_nonce_sent &&
    -        now > peer.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL}) {
    +        now > peer.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL} )
    +{
             LogPrint(BCLog::NET, "ping timeout: %fs peer=%d\n", 0.000001 * count_microseconds(now - peer.m_ping_start.load()), peer.m_id);
             node_to.fDisconnect = true;
             return;
    

    See also: https://clang.llvm.org/docs/ClangFormatStyleOptions.html Fixes #21735

  2. clang-format: Set BraceWrapping:AfterControlStatement:MultiLine facee3e229
  3. MarcoFalke added the label Docs on Oct 7, 2021
  4. practicalswift commented at 11:37 AM on October 7, 2021: contributor

    Concept ACK

  5. katesalazar commented at 3:45 PM on October 7, 2021: contributor

    FWIW concept ACK

  6. MarcoFalke commented at 1:40 PM on October 8, 2021: member

    Sorry, this doesn't function as expected, unless the column limit is set as well, as mentioned in the thread #21735

  7. MarcoFalke closed this on Oct 8, 2021

  8. MarcoFalke deleted the branch on Oct 8, 2021
  9. DrahtBot locked this on Oct 30, 2022

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: 2026-05-07 12:14 UTC

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