Differential D72282 Diff 240691 clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl-generic-lambdas.cpp
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/test/clang-tidy/checkers/bugprone-unintended-adl-generic-lambdas.cpp
- This file was added.
// RUN: %check_clang_tidy -std=c++14-or-later %s bugprone-unintended-adl %t | |||||
namespace std { | |||||
template <typename It, typename Pred> | |||||
It find_if(It begin, It end, Pred pred) { | |||||
for (; begin != end; ++begin) { | |||||
if (pred(*begin)) | |||||
break; | |||||
} | |||||
return begin; | |||||
} | |||||
} // namespace std | |||||
namespace ns { | |||||
struct S {}; | |||||
void foo(S); | |||||
void bar(S, S); | |||||
} // namespace ns | |||||
void foo(int); | |||||
void bar(int, int); | |||||
void test() { | |||||
{ | |||||
auto l = [](auto x) { foo(x); }; | |||||
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: expression calls 'ns::foo' through ADL [bugprone-unintended-adl] | |||||
// CHECK-MESSAGES: [[@LINE-2]]:27: note: with argument type 'struct ns::S' | |||||
// CHECK-MESSAGES: [[@LINE-3]]:27: warning: unqualified call to 'foo' may be resolved through ADL [bugprone-unintended-adl] | |||||
l(5); | |||||
l(ns::S()); | |||||
} | |||||
{ | |||||
auto l = [](auto x) { bar(x, x); }; | |||||
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: expression calls 'ns::bar' through ADL [bugprone-unintended-adl] | |||||
// CHECK-MESSAGES: [[@LINE-2]]:27: note: with argument types 'struct ns::S', 'struct ns::S' | |||||
// CHECK-MESSAGES: [[@LINE-3]]:27: warning: unqualified call to 'bar' may be resolved through ADL [bugprone-unintended-adl] | |||||
l(5); | |||||
l(ns::S()); | |||||
} | |||||
int x = 0; | |||||
[&](auto &c) { std::find_if(c.begin(), c.end(), | |||||
[&](auto &e) { return e.first == x; }); }; | |||||
[&](auto &c) { std::find_if(c.begin(), c.end(), | |||||
[&](auto &e) { return find_if(e, e, x); }); }; | |||||
// CHECK-MESSAGES: [[@LINE-1]]:53: warning: unqualified call to 'find_if' may be resolved through ADL [bugprone-unintended-adl] | |||||
} |