mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 19:37:27 -03:00
doc: Avoid ADL for function calls
This commit is contained in:
parent
c44e734dca
commit
52a797bfe5
1 changed files with 22 additions and 0 deletions
|
@ -105,6 +105,28 @@ code.
|
|||
- `nullptr` is preferred over `NULL` or `(void*)0`.
|
||||
- `static_assert` is preferred over `assert` where possible. Generally; compile-time checking is preferred over run-time checking.
|
||||
|
||||
For function calls a namespace should be specified explicitly, unless such functions have been declared within it.
|
||||
Otherwise, [argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl), also known as ADL, could be
|
||||
triggered that makes code harder to maintain and reason about:
|
||||
```c++
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs {
|
||||
class path : public std::filesystem::path
|
||||
{
|
||||
};
|
||||
// The intention is to disallow this function.
|
||||
bool exists(const fs::path& p) = delete;
|
||||
} // namespace fs
|
||||
|
||||
int main()
|
||||
{
|
||||
//fs::path p; // error
|
||||
std::filesystem::path p; // compiled
|
||||
exists(p); // ADL being used for unqualified name lookup
|
||||
}
|
||||
```
|
||||
|
||||
Block style example:
|
||||
```c++
|
||||
int g_count = 0;
|
||||
|
|
Loading…
Reference in a new issue