This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52522] New: Overloaded functions called with initializer lists considered ambiguous
- From: "dgsteffen at numerica dot us" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 07 Mar 2012 17:17:24 +0000
- Subject: [Bug c++/52522] New: Overloaded functions called with initializer lists considered ambiguous
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52522
Bug #: 52522
Summary: Overloaded functions called with initializer lists
considered ambiguous
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dgsteffen@numerica.us
Consider:
#include <vector>
using std::vector;
class Matrix{};
class Vector{};
Matrix horizontalConcat(const std::vector<Vector>& vectors);
Matrix horizontalConcat(const std::vector<Matrix>& matrices);
int main()
{
Matrix a,b;
horizontalConcat({a,b});
}
GCC 4.4 and 4.5 in C++0X mode (E.G., g++ testA.cpp -c -ansi -std=c++0x ) accept
this code and do the right thing. However, 4.6.3 produces:
/usr/local/compilers/4.6/bin/g++ testA.cpp -c -ansi -std=c++0x
estA.cpp: In function âint main()â:
testA.cpp:25:24: error: call of overloaded âhorizontalConcat(<brace-enclosed
initializer list>)â is ambiguous
testA.cpp:25:24: note: candidates are:
testA.cpp:12:8: note: Matrix horizontalConcat(const std::vector<Vector>&)
testA.cpp:13:8: note: Matrix horizontalConcat(const std::vector<Matrix>&)
However, sending an initializer list containing 3 or more Matrices works fine.
Also, removing the vector<Vector> overloaded function removes the warning.
In principle there could be some ambiguity, when using an initializer list of
two elements, between calling vector's initializer list ctor or calling one of
its other ctors, but here I don't see that either, since vector<Matrix> doesn't
have a ctor that takes two matrices.
At any rate, either GCC 4.6 is incorrectly concluding that the function call is
ambiguous, or it's producing a very confusing error message.
Thanks very much.