Skip to content

Commit 2f0f056

Browse files
committed
Merge bitcoin/bitcoin#24665: doc: document clang tidy named args
7e22d80 addrman: fix incorrect named args (fanquake) 67f654e doc: Document clang-tidy in dev notes (MarcoFalke) Pull request description: The documentation, and a single commit extracted from #24661. Motivation: > Incorrect named args are source of bugs, like bitcoin/bitcoin#22979. > To allow them being checked by clang-tidy, use a format it can understand. ACKs for top commit: glozow: ACK 7e22d80 Tree-SHA512: 4037fcea59fdf583b171bce7ad350299fe5f9feb3c398413432168f3b9a185e51884d5b30e4b4ab9c6c5bb896c178cfaee1d78d5b4f0034cd70121c9ea4184b7
2 parents 6d5771b + 7e22d80 commit 2f0f056

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

doc/developer-notes.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,57 @@ public:
137137
} // namespace foo
138138
```
139139

140+
Coding Style (C++ named arguments)
141+
------------------------------
142+
143+
When passing named arguments, use a format that clang-tidy understands. The
144+
argument names can otherwise not be verified by clang-tidy.
145+
146+
For example:
147+
148+
```c++
149+
void function(Addrman& addrman, bool clear);
150+
151+
int main()
152+
{
153+
function(g_addrman, /*clear=*/false);
154+
}
155+
```
156+
157+
### Running clang-tidy
158+
159+
To run clang-tidy on Ubuntu/Debian, install the dependencies:
160+
161+
```sh
162+
apt install clang-tidy bear clang
163+
```
164+
165+
Then, pass clang as compiler to configure, and use bear to produce the `compile_commands.json`:
166+
167+
```sh
168+
./autogen.sh && ./configure CC=clang CXX=clang++
169+
make clean && bear make -j $(nproc) # For bear 2.x
170+
make clean && bear -- make -j $(nproc) # For bear 3.x
171+
```
172+
173+
To run clang-tidy on all source files:
174+
175+
```sh
176+
( cd ./src/ && run-clang-tidy -j $(nproc) )
177+
```
178+
179+
To run clang-tidy on the changed source lines:
180+
181+
```sh
182+
git diff | ( cd ./src/ && clang-tidy-diff -p2 -j $(nproc) )
183+
```
184+
140185
Coding Style (Python)
141186
---------------------
142187

143188
Refer to [/test/functional/README.md#style-guidelines](/test/functional/README.md#style-guidelines).
144189

190+
145191
Coding Style (Doxygen-compatible comments)
146192
------------------------------------------
147193

src/addrman.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -946,16 +946,16 @@ std::optional<AddressPosition> AddrManImpl::FindAddressEntry_(const CAddress& ad
946946

947947
if(addr_info->fInTried) {
948948
int bucket{addr_info->GetTriedBucket(nKey, m_asmap)};
949-
return AddressPosition(/*tried=*/true,
950-
/*multiplicity=*/1,
951-
/*bucket=*/bucket,
952-
/*position=*/addr_info->GetBucketPosition(nKey, false, bucket));
949+
return AddressPosition(/*tried_in=*/true,
950+
/*multiplicity_in=*/1,
951+
/*bucket_in=*/bucket,
952+
/*position_in=*/addr_info->GetBucketPosition(nKey, false, bucket));
953953
} else {
954954
int bucket{addr_info->GetNewBucket(nKey, m_asmap)};
955-
return AddressPosition(/*tried=*/false,
956-
/*multiplicity=*/addr_info->nRefCount,
957-
/*bucket=*/bucket,
958-
/*position=*/addr_info->GetBucketPosition(nKey, true, bucket));
955+
return AddressPosition(/*tried_in=*/false,
956+
/*multiplicity_in=*/addr_info->nRefCount,
957+
/*bucket_in=*/bucket,
958+
/*position_in=*/addr_info->GetBucketPosition(nKey, true, bucket));
959959
}
960960
}
961961

0 commit comments

Comments
 (0)