public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13809] New: Template conversion operator reports ambiguity where none exists
@ 2004-01-22  5:49 gianni at mariani dot ws
  2004-01-22  8:29 ` [Bug c++/13809] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gianni at mariani dot ws @ 2004-01-22  5:49 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug c++/13809] Template conversion operator reports ambiguity where none exists
  2004-01-22  5:49 [Bug c++/13809] New: Template conversion operator reports ambiguity where none exists gianni at mariani dot ws
@ 2004-01-22  8:29 ` pinskia at gcc dot gnu dot org
  2004-01-22  8:37 ` gianni at mariani dot ws
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-22  8:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-22 08:29 -------
The problem is that GCC is taking in effect the default templates, this can either be a reject valid or 
accepts invalid as either can happen depending on if there is something that GCC will latch on or if 
there is two that GCC will latch on like this example.

Here is the reduced sources:
struct X
{

    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>();
    }

};

namespace std
{
template<typename> struct less{};
template<typename> struct allocator{};
template<typename A, typename B = std::less<A>,
  typename C = std::allocator<A> > struct set{};
}

int main()
{
    X   x;
    std::set<int>    s = x;
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, rejects-
                   |                            |valid


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


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

* [Bug c++/13809] Template conversion operator reports ambiguity where none exists
  2004-01-22  5:49 [Bug c++/13809] New: Template conversion operator reports ambiguity where none exists gianni at mariani dot ws
  2004-01-22  8:29 ` [Bug c++/13809] " pinskia at gcc dot gnu dot org
@ 2004-01-22  8:37 ` gianni at mariani dot ws
  2004-01-22  8:45 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gianni at mariani dot ws @ 2004-01-22  8:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gianni at mariani dot ws  2004-01-22 08:37 -------

Andrew, did you intentionally remove the 4 parameter conversion operator
template ?  std::set takes 4 parameters.  If I remember the standard correctly,
this is the conversion that should be used since it matches all parameters exactly.

-- 


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


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

* [Bug c++/13809] Template conversion operator reports ambiguity where none exists
  2004-01-22  5:49 [Bug c++/13809] New: Template conversion operator reports ambiguity where none exists gianni at mariani dot ws
  2004-01-22  8:29 ` [Bug c++/13809] " pinskia at gcc dot gnu dot org
  2004-01-22  8:37 ` gianni at mariani dot ws
@ 2004-01-22  8:45 ` pinskia at gcc dot gnu dot org
  2004-01-23 18:55 ` gianni at mariani dot ws
  2004-01-25 17:02 ` giovannibajo at libero dot it
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-22  8:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-22 08:45 -------
Actually I did that on accident but the standard says it is only three (23.3):
namespace std { template <class Key, class Compare = less<Key>, class Allocator = 
allocator<Key> > class set;  ...

So it does not matter if I did or did not.  The problem is still the same any ways.  Also sometimes if 
this is rejected and it should be reject GCC can also produce the wrong error message.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2004-01-22 08:45:46
               date|                            |


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


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

* [Bug c++/13809] Template conversion operator reports ambiguity where none exists
  2004-01-22  5:49 [Bug c++/13809] New: Template conversion operator reports ambiguity where none exists gianni at mariani dot ws
                   ` (2 preceding siblings ...)
  2004-01-22  8:45 ` pinskia at gcc dot gnu dot org
@ 2004-01-23 18:55 ` gianni at mariani dot ws
  2004-01-25 17:02 ` giovannibajo at libero dot it
  4 siblings, 0 replies; 6+ messages in thread
From: gianni at mariani dot ws @ 2004-01-23 18:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gianni at mariani dot ws  2004-01-23 18:55 -------
FYI - same error happens in the 3.4 snapshot - 21-Jan-2004.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|3.3.2                       |3.4.0


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


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

* [Bug c++/13809] Template conversion operator reports ambiguity where none exists
  2004-01-22  5:49 [Bug c++/13809] New: Template conversion operator reports ambiguity where none exists gianni at mariani dot ws
                   ` (3 preceding siblings ...)
  2004-01-23 18:55 ` gianni at mariani dot ws
@ 2004-01-25 17:02 ` giovannibajo at libero dot it
  4 siblings, 0 replies; 6+ messages in thread
From: giovannibajo at libero dot it @ 2004-01-25 17:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-01-25 17:02 -------
This is a known issue. I'm revisiting our position on it right now.

*** This bug has been marked as a duplicate of 9737 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


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


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

end of thread, other threads:[~2004-01-25 17:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-22  5:49 [Bug c++/13809] New: Template conversion operator reports ambiguity where none exists gianni at mariani dot ws
2004-01-22  8:29 ` [Bug c++/13809] " pinskia at gcc dot gnu dot org
2004-01-22  8:37 ` gianni at mariani dot ws
2004-01-22  8:45 ` pinskia at gcc dot gnu dot org
2004-01-23 18:55 ` gianni at mariani dot ws
2004-01-25 17:02 ` giovannibajo at libero dot it

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).