From 67f654ef612c8dbefb969e6e67c286ea2c2e82d6 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 18 Nov 2021 20:04:22 +0100 Subject: [PATCH 1/2] doc: Document clang-tidy in dev notes --- doc/developer-notes.md | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index bfb64093e1..c3ab3fa953 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -137,11 +137,57 @@ public: } // namespace foo ``` +Coding Style (C++ named arguments) +------------------------------ + +When passing named arguments, use a format that clang-tidy understands. The +argument names can otherwise not be verified by clang-tidy. + +For example: + +```c++ +void function(Addrman& addrman, bool clear); + +int main() +{ + function(g_addrman, /*clear=*/false); +} +``` + +### Running clang-tidy + +To run clang-tidy on Ubuntu/Debian, install the dependencies: + +```sh +apt install clang-tidy bear clang +``` + +Then, pass clang as compiler to configure, and use bear to produce the `compile_commands.json`: + +```sh +./autogen.sh && ./configure CC=clang CXX=clang++ +make clean && bear make -j $(nproc) # For bear 2.x +make clean && bear -- make -j $(nproc) # For bear 3.x +``` + +To run clang-tidy on all source files: + +```sh +( cd ./src/ && run-clang-tidy -j $(nproc) ) +``` + +To run clang-tidy on the changed source lines: + +```sh +git diff | ( cd ./src/ && clang-tidy-diff -p2 -j $(nproc) ) +``` + Coding Style (Python) --------------------- Refer to [/test/functional/README.md#style-guidelines](/test/functional/README.md#style-guidelines). + Coding Style (Doxygen-compatible comments) ------------------------------------------ From 7e22d80af333b202939bcb2631082006c097bf22 Mon Sep 17 00:00:00 2001 From: fanquake Date: Thu, 24 Mar 2022 15:12:31 +0000 Subject: [PATCH 2/2] addrman: fix incorrect named args --- src/addrman.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 2fd8143c1c..2a08d99eef 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -946,16 +946,16 @@ std::optional AddrManImpl::FindAddressEntry_(const CAddress& ad if(addr_info->fInTried) { int bucket{addr_info->GetTriedBucket(nKey, m_asmap)}; - return AddressPosition(/*tried=*/true, - /*multiplicity=*/1, - /*bucket=*/bucket, - /*position=*/addr_info->GetBucketPosition(nKey, false, bucket)); + return AddressPosition(/*tried_in=*/true, + /*multiplicity_in=*/1, + /*bucket_in=*/bucket, + /*position_in=*/addr_info->GetBucketPosition(nKey, false, bucket)); } else { int bucket{addr_info->GetNewBucket(nKey, m_asmap)}; - return AddressPosition(/*tried=*/false, - /*multiplicity=*/addr_info->nRefCount, - /*bucket=*/bucket, - /*position=*/addr_info->GetBucketPosition(nKey, true, bucket)); + return AddressPosition(/*tried_in=*/false, + /*multiplicity_in=*/addr_info->nRefCount, + /*bucket_in=*/bucket, + /*position_in=*/addr_info->GetBucketPosition(nKey, true, bucket)); } }