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-
maflcko commented at 4:52 pm on January 20, 2026: memberThe typo is harmless, but a bit confusing every time i read it
-
DrahtBot added the label Docs on Jan 20, 2026
-
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.
If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.
-
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 theintabove.
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:jis different than(j). One is int, the other is&intafter decltype(auto) return type deduction0#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}
maflcko commented at 11:41 am on January 22, 2026:Also, with C++23, it will beint&&: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2266r3.html#decltype-autoin 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:We usually don’t have a;inside, e.g.: https://github.com/bitcoin/bitcoin/blob/7f5ebef56a0f2bad7df30252b11da3e33cb3c144/src/net.h#L429
maflcko commented at 5:46 pm on January 20, 2026:Correct. However, the docs here exist to explaindecltype(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 thatl0rinc changes_requestedhebasto approvedhebasto commented at 1:35 pm on January 21, 2026: memberACK 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.
doc: Fix wrong code in WITH_LOCK doxygen comment fa61fadad1maflcko force-pushed on Jan 21, 2026hebasto approvedhebasto commented at 2:05 pm on January 21, 2026: memberre-ACK fa61fadad1c3df0274c3ddd351b8d68a0c4fe644.l0rinc commented at 10:21 am on January 22, 2026: contributorACK fa61fadad1c3df0274c3ddd351b8d68a0c4fe644hebasto merged this on Jan 22, 2026hebasto closed this on Jan 22, 2026
maflcko deleted the branch on Jan 22, 2026
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
More mirrored repositories can be found on mirror.b10c.me