Skip to content

Commit 0e94f23

Browse files
committed
Example of shutting down ADL.
1 parent 7aeabb3 commit 0e94f23

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

code_examples/theory/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ add_executable(adl_simple adl_simple.cpp)
2121

2222
add_executable(adl_nonfunc adl_nonfunc.cpp)
2323
# Compile only
24+
25+
add_executable(adl_shutdown adl_shutdown.cpp)
26+
# Compile only

code_examples/theory/adl_shutdown.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "adl_shutdown_code.h"
2+
int main() {
3+
calling_site();
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Custom {
2+
struct X {
3+
friend void some_func(const X&) {}
4+
};
5+
}
6+
7+
constexpr inline auto some_func = [](const auto&) {};
8+
9+
void calling_site() {
10+
Custom::X x;
11+
some_func(x); // calls ::some_func
12+
// Because ::some_func prevents ADL, Custom::some_func cannot be called.
13+
}

0 commit comments

Comments
 (0)