This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13809] New: Template conversion operator reports ambiguity where none exists


The code below compiles fine on Comeau and VC++ 7.1.

Error:

t29x.cpp: In function `int main()':
t29x.cpp:33: error: conversion from `X' to `std::set<int, std::less<int>,
   std::allocator<int> >' is ambiguous
t29x.cpp:9: error: candidates are: X::operator C<T, A>() [with T = int, A =
   std::less<int>, C = std::set]
t29x.cpp:15: error:                 X::operator C<T, A, B>() [with T = int, A =
   std::less<int>, B = std::allocator<int>, C = std::set]

Note that std::set is a 4 parameter template yet the ambiguity is reported on 2
and 3 parameters.  It appears the wrong logic is being used to deduce which
conversion operator to use.

So here's the code:

struct X
{
    struct C; //uncomment to make this work - see bug:13808

    template<typename T, typename A, template<typename,typename> class C>
        operator C<T, A > ()
    {
        return C<T, A>();
    }

    template<typename T, typename A, typename B,
template<typename,typename,typename> class C >
    operator C<T, A, B> ()
    {
        return C<T, A, B>();
    }

    template<typename T, typename A, typename B, typename Z,
template<typename,typename,typename,typename> class C >
    operator C<T, A, B, Z> ()
    {
        return C<T, A, B, Z>();
    }

};

#include <set>

int main()
{
    X   x;

    std::set<int>    s = x;
}

-- 
           Summary: Template conversion operator reports ambiguity where
                    none exists
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gianni at mariani dot ws
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13809


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]