ADL now explicitly prohibits finding non-functions
[ I posted this some time ago in comp.std.c++, but it did not
appear. I am guessing it was rejected, but my address is
mangled, so I wasn't notified either way. Perhaps somebody
here will have an answer... ]
Hello,
Recently we had a discussion in comp.lang.c++ about ADL and its
effects on finding non-function names. Here is example code:
namespace A {
struct Foo {};
struct ff {
ff() {}
ff(const Foo&) {}
void operator()(const Foo&) {}
};
ff f; // global object of type 'ff'
void fff(const Foo&) {}
} // namespace A
// global functions
void f(const A::Foo&) {}
void ff(const A::Foo&) {}
void fff(const A::Foo&) {}
int main() {
f(A::Foo()); // f.operator()(A::Foo())?
ff(A::Foo()); // temporary of type 'ff'?
fff(A::Foo()); // which function?
}
According to the new version (draft) of the Standard, with the added
third bullet to the list at the end of [basic.lookup.argdep]/4, the
object or the type are not found, making only 'fff' ambiguous. In
the current Standard (2003), however, both the 'ff' type and the 'f'
object *can* be construed as "findable", and as far as we could see,
G++ does find those thus flagging all three statements in 'main' as
containing errors.
The concern that we have is that limiting the lookup to function only
may end up breaking code like this:
namespace A {
struct Foo {};
struct ff {
ff() {}
void operator()(const Foo&) {}
};
ff f; // global object of type 'ff'
} // namespace A
int main() {
f(A::Foo()); // f.operator()(A::Foo())
}
where no ambiguity existed (at least in G++ implementors' minds).
What was the reason for the change in [basic.lookup.argdep]/4 (I
couldn't find the document or the discussion for it on Committee
web pages), and has the situation with functors been considered?
Thanks!
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]