Skip to content

Commit 52a797b

Browse files
committed
doc: Avoid ADL for function calls
1 parent c44e734 commit 52a797b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/developer-notes.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ code.
105105
- `nullptr` is preferred over `NULL` or `(void*)0`.
106106
- `static_assert` is preferred over `assert` where possible. Generally; compile-time checking is preferred over run-time checking.
107107

108+
For function calls a namespace should be specified explicitly, unless such functions have been declared within it.
109+
Otherwise, [argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl), also known as ADL, could be
110+
triggered that makes code harder to maintain and reason about:
111+
```c++
112+
#include <filesystem>
113+
114+
namespace fs {
115+
class path : public std::filesystem::path
116+
{
117+
};
118+
// The intention is to disallow this function.
119+
bool exists(const fs::path& p) = delete;
120+
} // namespace fs
121+
122+
int main()
123+
{
124+
//fs::path p; // error
125+
std::filesystem::path p; // compiled
126+
exists(p); // ADL being used for unqualified name lookup
127+
}
128+
```
129+
108130
Block style example:
109131
```c++
110132
int g_count = 0;

0 commit comments

Comments
 (0)