Skip to content

Commit

Permalink
Merge #24665: doc: document clang tidy named args
Browse files Browse the repository at this point in the history
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 #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
  • Loading branch information
fanquake committed Mar 25, 2022
2 parents 6d5771b + 7e22d80 commit 2f0f056
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
46 changes: 46 additions & 0 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------------------------------

Expand Down
16 changes: 8 additions & 8 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,16 +946,16 @@ std::optional<AddressPosition> 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));
}
}

Expand Down

0 comments on commit 2f0f056

Please sign in to comment.