Enclose all header content in include guards #36805

pull hebasto wants to merge 5 commits into bitcoin:master from hebasto:261108-include-guard changing 16 files +81 −49
  1. hebasto commented at 4:17 PM on November 8, 2026: member

    From https://gcc.gnu.org/onlinedocs/cpp/Once-Only-Headers.html:

    If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g. when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time.

    This PR fixes the three headers that have content outside their guards and modifies test/lint/lint-include-guards.py to catch such violations in the future.

    A prerequisite for #36808.

  2. DrahtBot commented at 4:17 PM on November 8, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Stale ACK jpk68

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. jpk68 commented at 7:27 PM on November 8, 2026: contributor

    ACK c385c1ff18b5f7e5bb0ff658bc5ba467897904ec

  4. in test/lint/lint-include-guards.py:69 in c385c1ff18 outdated
      60 | @@ -61,6 +61,27 @@ def _get_header_id(header_file: str) -> str:
      61 |      return header_id
      62 |  
      63 |  
      64 | +def _is_comment_or_blank(line: str, in_block_comment: bool) -> tuple[bool, bool]:
      65 | +    """ Helper function to tell whether a line carries no code.
      66 | +
      67 | +    Args:
      68 | +        line: A line of the header file.
      69 | +        in_block_comment: Whether the previous line left a /* ... */ comment open.
    


    maflcko commented at 7:13 AM on November 9, 2026:

    We don't use /* comments for the header and we shouldn't start doing that, so this dead logic should be dropped



    maflcko commented at 10:31 AM on November 9, 2026:

    Sure, but they are wrong, because doxygen doesn't attach them to the guard, but to the next variable:

    [DEFAULT_TOR_SOCKS_PORT](https://doxygen.bitcoincore.org/torcontrol_8h.html#a3213ad4529bf3b1a9a0665ce210d19b1) {9050}
     	Functionality for communicating with Tor. 
    

    Implying that this would be possible doesn't seem useful. I guess I missed that there are existing violations, but it may be best to fix them instead of ignoring them?


    hebasto commented at 2:13 PM on November 9, 2026:

    Right. Fixed in #36815.

    Marking this PR as a draft for now.

  5. hebasto marked this as a draft on Nov 9, 2026
  6. doc: Fix Doxygen attribution of file-level comments
    Without an explicit @file command, Doxygen attached these comments to
    the next declaration.
    c7ebbbba6c
  7. doc: Fix `@file` descriptions that start with the file name
    Doxygen treats the word after `@file` as the name of the documented
    file and drops it from the text. Use a bare `@file` and `@brief`
    instead.
    
    Co-Authored-By: fanquake <fanquake@gmail.com>
    4cb432772c
  8. doc: Attach `subprocess.h` header comment to the file
    Add `@file` and `@brief` so Doxygen documents the file rather than the
    `subprocess_close` macro.
    
    Also move the whole comment block inside the include guard. This
    simplifies upcoming changes to the include guard linter.
    c4a68cc5ce
  9. Enclose all header content in include guards 6376e3cd70
  10. hebasto force-pushed on Nov 9, 2026
  11. lint: Require all code in a header to be inside its include guard
    Flag any non-comment line before `#ifndef` or after `#endif`.
    c047655f35
  12. hebasto force-pushed on Nov 9, 2026
  13. DrahtBot added the label CI failed on Nov 9, 2026
  14. DrahtBot removed the label CI failed on Nov 9, 2026

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-11-09 21:51 UTC

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