Let's say that I have a setup like this:
namespace hi {
template<typename L, typename R> L operator+(L l, R r) {
// some body
}
auto f() {
return [] {}; // Legal C++14
}
}
int main() {
auto x = hi::f();
1 + x; // Is this legal?
}
The question is whether ADL on the lambda type will find the overloaded operator in that namespace by Standard.
C++11 says (5.1.2, p3) that the type of a lambda will be declared "in the smallest block scope, class scope, or namespace scope that contains the corresponding lambda-expression.
" So in this case, the type will be declared in f
. C++14's CD has the same language.
So the question really is what the namespace for a local class is. I don't think it has one.
C++11, section 9.8, p1, states: The name of a local class is local to its enclosing scope.
As such, I don't believe that it has any associated namespaces (per 3.4.2, p2), and is therefore not subject to ADL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With