www.digitalmars.com         C & C++   DMDScript  

c++ - Conversion member template bug

reply "Matthew Wilson" <dmd synesis.com.au> writes:
Not sure if this is covered by Christof's comprehensive coverage, but here
is just in case


struct S
{
// Construction
public:
    S(int i)
        : m_i(i)
    {}

// Conversion
public:
    template <class T>
    operator T () const
    {
        return (T)m_i;
    }

// Members
protected:
    int     m_i;
};

void fn(int )
{}

int main(int, char**)
{
    S   s(100);

    fn(s);

    return 0;
}

The 8.32.12b gives

H:\Dev\Test\compiler\dm\null_v_bug>dmc optbug.cpp
optbug.cpp(15) : Error: 'S::operator int' is already defined
        fn(s);
             ^
optbug.cpp(41) : Error: need explicit cast for function parameter 1 to get
from: S
to  : int
--- errorlevel 1

If I changes the fn call to

    fn((int)s);

then it works, but that kind-of defeats the purpose. ;)

Matthew
Dec 16 2002
parent reply "Matthew Wilson" <dmd synesis.com.au> writes:
Walter

Any ETA with this one ... :)

Matthew

"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:atlkke$2d99$1 digitaldaemon.com...
 Not sure if this is covered by Christof's comprehensive coverage, but here
 is just in case


 struct S
 {
 // Construction
 public:
     S(int i)
         : m_i(i)
     {}

 // Conversion
 public:
     template <class T>
     operator T () const
     {
         return (T)m_i;
     }

 // Members
 protected:
     int     m_i;
 };

 void fn(int )
 {}

 int main(int, char**)
 {
     S   s(100);

     fn(s);

     return 0;
 }

 The 8.32.12b gives

 H:\Dev\Test\compiler\dm\null_v_bug>dmc optbug.cpp
 optbug.cpp(15) : Error: 'S::operator int' is already defined
         fn(s);
              ^
 optbug.cpp(41) : Error: need explicit cast for function parameter 1 to get
 from: S
 to  : int
 --- errorlevel 1

 If I changes the fn call to

     fn((int)s);

 then it works, but that kind-of defeats the purpose. ;)

 Matthew
Dec 17 2002
parent reply "Walter" <walter digitalmars.com> writes:
Orsen Welles comes to mind <g>.

"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:atoi7h$1hmn$1 digitaldaemon.com...
 Walter

 Any ETA with this one ... :)

 Matthew

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atlkke$2d99$1 digitaldaemon.com...
 Not sure if this is covered by Christof's comprehensive coverage, but
here
 is just in case


 struct S
 {
 // Construction
 public:
     S(int i)
         : m_i(i)
     {}

 // Conversion
 public:
     template <class T>
     operator T () const
     {
         return (T)m_i;
     }

 // Members
 protected:
     int     m_i;
 };

 void fn(int )
 {}

 int main(int, char**)
 {
     S   s(100);

     fn(s);

     return 0;
 }

 The 8.32.12b gives

 H:\Dev\Test\compiler\dm\null_v_bug>dmc optbug.cpp
 optbug.cpp(15) : Error: 'S::operator int' is already defined
         fn(s);
              ^
 optbug.cpp(41) : Error: need explicit cast for function parameter 1 to
get
 from: S
 to  : int
 --- errorlevel 1

 If I changes the fn call to

     fn((int)s);

 then it works, but that kind-of defeats the purpose. ;)

 Matthew
Dec 17 2002
parent reply "Matthew Wilson" <dmd synesis.com.au> writes:
You've completely lost me, Walter. Either you're more inscrutable than I can
handle, or I've been so much documentation that my brain has turned to
sandstone.

"Walter" <walter digitalmars.com> wrote in message
news:atoj5d$1i8t$1 digitaldaemon.com...
 Orsen Welles comes to mind <g>.

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atoi7h$1hmn$1 digitaldaemon.com...
 Walter

 Any ETA with this one ... :)

 Matthew

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atlkke$2d99$1 digitaldaemon.com...
 Not sure if this is covered by Christof's comprehensive coverage, but
here
 is just in case


 struct S
 {
 // Construction
 public:
     S(int i)
         : m_i(i)
     {}

 // Conversion
 public:
     template <class T>
     operator T () const
     {
         return (T)m_i;
     }

 // Members
 protected:
     int     m_i;
 };

 void fn(int )
 {}

 int main(int, char**)
 {
     S   s(100);

     fn(s);

     return 0;
 }

 The 8.32.12b gives

 H:\Dev\Test\compiler\dm\null_v_bug>dmc optbug.cpp
 optbug.cpp(15) : Error: 'S::operator int' is already defined
         fn(s);
              ^
 optbug.cpp(41) : Error: need explicit cast for function parameter 1 to
get
 from: S
 to  : int
 --- errorlevel 1

 If I changes the fn call to

     fn((int)s);

 then it works, but that kind-of defeats the purpose. ;)

 Matthew
Dec 17 2002
parent reply "Walter" <walter digitalmars.com> writes:
Orsen Welles selling Gallo wine: "We will sell no wine before its time."
Often parodied at the time, but I suppose it's been too many years <g>.

"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:atone6$1l4v$1 digitaldaemon.com...
 You've completely lost me, Walter. Either you're more inscrutable than I
can
 handle, or I've been so much documentation that my brain has turned to
 sandstone.

 "Walter" <walter digitalmars.com> wrote in message
 news:atoj5d$1i8t$1 digitaldaemon.com...
 Orsen Welles comes to mind <g>.

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atoi7h$1hmn$1 digitaldaemon.com...
 Walter

 Any ETA with this one ... :)

 Matthew

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atlkke$2d99$1 digitaldaemon.com...
 Not sure if this is covered by Christof's comprehensive coverage,
but
 here
 is just in case


 struct S
 {
 // Construction
 public:
     S(int i)
         : m_i(i)
     {}

 // Conversion
 public:
     template <class T>
     operator T () const
     {
         return (T)m_i;
     }

 // Members
 protected:
     int     m_i;
 };

 void fn(int )
 {}

 int main(int, char**)
 {
     S   s(100);

     fn(s);

     return 0;
 }

 The 8.32.12b gives

 H:\Dev\Test\compiler\dm\null_v_bug>dmc optbug.cpp
 optbug.cpp(15) : Error: 'S::operator int' is already defined
         fn(s);
              ^
 optbug.cpp(41) : Error: need explicit cast for function parameter 1
to
 get
 from: S
 to  : int
 --- errorlevel 1

 If I changes the fn call to

     fn((int)s);

 then it works, but that kind-of defeats the purpose. ;)

 Matthew
Dec 17 2002
parent reply "Matthew Wilson" <dmd synesis.com.au> writes:
No worries. I have a little patience on this matter ... :)



"Walter" <walter digitalmars.com> wrote in message
news:atp3so$1tlk$1 digitaldaemon.com...
 Orsen Welles selling Gallo wine: "We will sell no wine before its time."
 Often parodied at the time, but I suppose it's been too many years <g>.

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atone6$1l4v$1 digitaldaemon.com...
 You've completely lost me, Walter. Either you're more inscrutable than I
can
 handle, or I've been so much documentation that my brain has turned to
 sandstone.

 "Walter" <walter digitalmars.com> wrote in message
 news:atoj5d$1i8t$1 digitaldaemon.com...
 Orsen Welles comes to mind <g>.

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atoi7h$1hmn$1 digitaldaemon.com...
 Walter

 Any ETA with this one ... :)

 Matthew

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atlkke$2d99$1 digitaldaemon.com...
 Not sure if this is covered by Christof's comprehensive coverage,
but
 here
 is just in case


 struct S
 {
 // Construction
 public:
     S(int i)
         : m_i(i)
     {}

 // Conversion
 public:
     template <class T>
     operator T () const
     {
         return (T)m_i;
     }

 // Members
 protected:
     int     m_i;
 };

 void fn(int )
 {}

 int main(int, char**)
 {
     S   s(100);

     fn(s);

     return 0;
 }

 The 8.32.12b gives

 H:\Dev\Test\compiler\dm\null_v_bug>dmc optbug.cpp
 optbug.cpp(15) : Error: 'S::operator int' is already defined
         fn(s);
              ^
 optbug.cpp(41) : Error: need explicit cast for function parameter
1
 to
 get
 from: S
 to  : int
 --- errorlevel 1

 If I changes the fn call to

     fn((int)s);

 then it works, but that kind-of defeats the purpose. ;)

 Matthew
Dec 18 2002
parent reply "Walter" <walter digitalmars.com> writes:
In any case, I fixed it and it'll go out in the next update. -Walter

"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:atpcqb$2513$1 digitaldaemon.com...
 No worries. I have a little patience on this matter ... :)
Dec 18 2002
parent "Matthew Wilson" <dmd synesis.com.au> writes:
Excellent stuff! (As usual)

We again doff our collective cap to the esteemed compiler walter. :)

"Walter" <walter digitalmars.com> wrote in message
news:atpj7q$29rm$1 digitaldaemon.com...
 In any case, I fixed it and it'll go out in the next update. -Walter

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:atpcqb$2513$1 digitaldaemon.com...
 No worries. I have a little patience on this matter ... :)
Dec 18 2002