[cfe-dev] Feature request: C++ diagnostic for ambiguous overloads
Nathan Ridge
zeratul976 at hotmail.com
Thu May 17 19:01:00 PDT 2012
Hi,
I have a feature request regarding a compiler diagnostic.
When a call of an overloaded function is ambiguous, and some of the candidates
are declared in namespaces other than the namespace of the call site (or one
of its parent namespaces), it would be helpful if the compiler helped us
figure out why those candidates are visible in the namespace of the call site.
Specifically, it would be helpful if the compiler would say:
- whether the candidate is visible 1) because it was imported into the
namespace of the call site (or one of its parent namespaces) via a
using-declaration or a using-directive, OR 2) because it was found
using argument-dependent lookup
- in the first case, the location of the using-declaration or using-
directive (if there are several, any one of them should suffice)
- in the second case, the argument that triggered the argument-
dependent lookup and why
Examples:
/////////////// EXAMPLE 1 ///////////////
namespace n1
{
void foo(double);
}
using n1::foo;
void foo(float);
int main()
{
foo(0);
}
// Current diagnostic
test.cpp:12:4: error: call to 'foo' is ambiguous
foo(0);
^~~
test.cpp:3:10: note: candidate function
void foo(double);
^
test.cpp:8:6: note: candidate function
void foo(float);
^
// What I would like to see
test.cpp:12:4: error: call to 'foo' is ambiguous
foo(0);
^~~
test.cpp:3:10: note: candidate function
void foo(double);
^
test.cpp:6:13: note: found due to using-declaration here
using n1::foo;
^
test.cpp:8:6: note: candidate function
void foo(float);
^
/////////////// EXAMPLE 2 ///////////////
namespace n1
{
struct Bar {};
void foo(double, Bar);
}
void foo(float, n1::Bar);
int main()
{
foo(0, n1::Bar());
}
// Current diagnostic
test.cpp:12:4: error: call to 'foo' is ambiguous
foo(0, n1::Bar());
^~~
test.cpp:5:10: note: candidate function
void foo(double, Bar);
^
test.cpp:8:6: note: candidate function
void foo(float, n1::Bar);
^
// What I would like to see
test.cpp:12:4: error: call to 'foo' is ambiguous
foo(0, n1::Bar());
^~~
test.cpp:5:10: note: candidate function
void foo(double, Bar);
^
test.cpp:12:11: note: found by argument-dependent lookup because 'n1' is an associated namespace of argument 2 of type 'n1::Bar'
foo(0, n1::Bar());
^~~~~~~~~
test.cpp:8:6: note: candidate function
void foo(float, n1::Bar);
^
//////////////////////////////////////////
Does this sound doable? Should I file a bugzilla entry?
Thanks,
Nate
More information about the cfe-dev
mailing list