doc: Fix wrong code in WITH_LOCK doxygen comment #34355

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2601-doc-fix-code changing 1 files +2 −2
  1. maflcko commented at 4:52 pm on January 20, 2026: member
    The typo is harmless, but a bit confusing every time i read it
  2. DrahtBot added the label Docs on Jan 20, 2026
  3. DrahtBot commented at 4:52 pm on January 20, 2026: 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/34355.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto, l0rinc

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  4. in src/sync.h:284 in fa07e52616
    281+//!   WITH_LOCK(cs, int i = 1; return i;);
    282 //!
    283 //! is int, the deduced type of:
    284 //!
    285-//!   WITH_LOCK(cs, return {int j = 1; return (j);});
    286+//!   WITH_LOCK(cs, int j = 1; return (j););
    


    l0rinc commented at 5:10 pm on January 20, 2026:
    what’s the purpose of (j)?

    maflcko commented at 5:47 pm on January 20, 2026:
    It is used to explain &int, which is different than the int above.

    l0rinc commented at 10:20 am on January 22, 2026:

    Do you mean that

    0//!   WITH_LOCK(cs, int j = 1; return j);
    

    wouldn’t work, only

    0//!   WITH_LOCK(cs, int j = 1; return (j));
    

    ? Why do we need to group it, not sure I understand?


    maflcko commented at 10:53 am on January 22, 2026:

    j is different than (j). One is int, the other is &int after decltype(auto) return type deduction

     0#include <type_traits>
     1
     2#define WITH_CODE(code) [&]() -> decltype(auto) { code; }()
     3
     4int main() {
     5    // Case 1: returns int (by value)
     6    static_assert(
     7        std::is_same_v<decltype(WITH_CODE(int i = 1; return i;)), int>);
     8
     9    // Case 2: returns int& (reference to local variable)
    10    static_assert(
    11        std::is_same_v<decltype(WITH_CODE(int j = 1; return (j);)), int&>);
    12
    13    // Compile-time check for reference-to-local
    14    static_assert(std::is_lvalue_reference_v<decltype(WITH_CODE(int k = 1;
    15                                                                return (k);))>);
    16}
    

    https://godbolt.org/z/ez6d7dz3T


    maflcko commented at 11:41 am on January 22, 2026:
  5. in src/sync.h:280 in fa07e52616
    276@@ -277,11 +277,11 @@ inline MutexType* MaybeCheckNotHeld(MutexType* m) LOCKS_EXCLUDED(m) LOCK_RETURNE
    277 //! Since the return type deduction follows that of decltype(auto), while the
    278 //! deduced type of:
    279 //!
    280-//!   WITH_LOCK(cs, return {int i = 1; return i;});
    281+//!   WITH_LOCK(cs, int i = 1; return i;);
    


    l0rinc commented at 5:10 pm on January 20, 2026:

    maflcko commented at 5:46 pm on January 20, 2026:
    Correct. However, the docs here exist to explain decltype(auto).

    maflcko commented at 1:52 pm on January 21, 2026:
    i guess i didn’t understand the comment here. the first semicolon is required, but the second can be removed, so i did that
  6. l0rinc changes_requested
  7. hebasto approved
  8. hebasto commented at 1:35 pm on January 21, 2026: member

    ACK fa07e5261666c808613d9ce9c201cc7a0ca6b80e, the current code snippets have wrong syntax.

    I agree with #34355 (review), as the semicolon is now trailing and should be dropped. Happy to re-ACK once this is addressed.

  9. doc: Fix wrong code in WITH_LOCK doxygen comment fa61fadad1
  10. maflcko force-pushed on Jan 21, 2026
  11. hebasto approved
  12. hebasto commented at 2:05 pm on January 21, 2026: member
    re-ACK fa61fadad1c3df0274c3ddd351b8d68a0c4fe644.
  13. l0rinc commented at 10:21 am on January 22, 2026: contributor
    ACK fa61fadad1c3df0274c3ddd351b8d68a0c4fe644
  14. hebasto merged this on Jan 22, 2026
  15. hebasto closed this on Jan 22, 2026

  16. maflcko deleted the branch on Jan 22, 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-01-22 18:13 UTC

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