public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52522] New: Overloaded functions called with initializer lists considered ambiguous
@ 2012-03-07 17:17 dgsteffen at numerica dot us
  2012-03-07 18:33 ` [Bug c++/52522] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: dgsteffen at numerica dot us @ 2012-03-07 17:17 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-08 18:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-07 17:17 [Bug c++/52522] New: Overloaded functions called with initializer lists considered ambiguous dgsteffen at numerica dot us
2012-03-07 18:33 ` [Bug c++/52522] " redi at gcc dot gnu.org
2012-03-07 18:41 ` daniel.kruegler at googlemail dot com
2012-03-07 18:45 ` redi at gcc dot gnu.org
2012-03-07 19:07 ` dgsteffen at numerica dot us
2012-03-08 18:35 ` daniel.kruegler at googlemail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).