You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by fa...@apache.org on 2007/05/25 15:13:17 UTC

svn commit: r541635 - /incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp

Author: faridz
Date: Fri May 25 06:13:16 2007
New Revision: 541635

URL: http://svn.apache.org/viewvc?view=rev&rev=541635
Log:
2007-05-25 Farid Zaripov <Fa...@epam.com>

	STDCXX-378
	* dynatype.cpp: Removed dynatype::operator T&() to resolve
	ambiguity between user defined conversions on MSVC.

Modified:
    incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp

Modified: incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp?view=diff&rev=541635&r1=541634&r2=541635
==============================================================================
--- incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp (original)
+++ incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp Fri May 25 06:13:16 2007
@@ -88,20 +88,13 @@
         (this->*p_remove)();
     }
 
-    // retrieve a reference to the concrete type from an instance of
+    // retrieve a value of the concrete type from an instance of
     // dynatype throws std::bad_cast if the types don't match exactly
     template <class T>
-    operator T& () {
+    operator T () const {
         if (map<T>::get ().end () == map<T>::get ().find (this))
             throw std::bad_cast ();
         return map<T>::get () [this];
-    }
-
-    // retrieve a value of the concrete type from an instance of
-    // dynatype throws std::bad_cast if the types don't match exactly
-    template <class T>
-    operator T () const {
-        return static_cast<T&> (*const_cast<dynatype*>(this));
     }
 
     // assign a value of any type to an instance of dynatype



Re: svn commit: r541635 - /incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Martin Sebor [mailto:sebor@roguewave.com] 
>> Sent: Friday, May 25, 2007 10:42 PM
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: svn commit: r541635 - 
>> /incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp
>>
>> Btw., I tried to get the test case you submitted to Microsoft
>> https://connect.microsoft.com/VisualStudio/feedback/ViewFeedba
>> ck.aspx?FeedbackID=266262
>> to work and changing class test like this did it:
>>
>>      struct test {
>>          template <class T> operator T& ();
>>          template <class T> operator const T& () const;
>>      };
>>
>> Does it work in the full example?
> 
>   It works fine on the MSVC 8.0. But MSVC 7.1 issues the different
> errors,
> depending on the order of using dynatype::operator const T& (). In
> original
> order the compiler complains only about unable to convert from dynatype
> to char.
> When I've changed the type char to int, the example compiled
> successfully,
> but linker did not found the external symbol dynatype::operator<double>
> const double & ().
> When I've exchanged the types double and int, the linker complained
> about external symbol
> dynatype::operator<int> const int & ().

So those are bugs in MSVC 7.1. But at least the example now
compiles with MSVC 8. It would be nice if it compiled with
both but I don't think it's necessary to any more trouble
than we already have to accommodate an old compiler that's
already been superseded by a more conforming release.

Thanks again!
Martin

RE: svn commit: r541635 - /incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com] 
> Sent: Friday, May 25, 2007 10:42 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r541635 - 
> /incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp
> 
> Btw., I tried to get the test case you submitted to Microsoft
> https://connect.microsoft.com/VisualStudio/feedback/ViewFeedba
> ck.aspx?FeedbackID=266262
> to work and changing class test like this did it:
> 
>      struct test {
>          template <class T> operator T& ();
>          template <class T> operator const T& () const;
>      };
> 
> Does it work in the full example?

  It works fine on the MSVC 8.0. But MSVC 7.1 issues the different
errors,
depending on the order of using dynatype::operator const T& (). In
original
order the compiler complains only about unable to convert from dynatype
to char.
When I've changed the type char to int, the example compiled
successfully,
but linker did not found the external symbol dynatype::operator<double>
const double & ().
When I've exchanged the types double and int, the linker complained
about external symbol
dynatype::operator<int> const int & ().

  
Farid.

Re: svn commit: r541635 - /incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp

Posted by Martin Sebor <se...@roguewave.com>.
faridz@apache.org wrote:
> Author: faridz
> Date: Fri May 25 06:13:16 2007
> New Revision: 541635
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=541635
> Log:
> 2007-05-25 Farid Zaripov <Fa...@epam.com>
> 
> 	STDCXX-378
> 	* dynatype.cpp: Removed dynatype::operator T&() to resolve
> 	ambiguity between user defined conversions on MSVC.

Hmm. This isn't quite the same thing as the original code, even
though it doesn't change the behavior of the example program
itself. The change makes it impossible to retrieve a reference
(or pointer) to the object stored in the dynatype object. For
example, this won't work:

     dynatype d = 1;
     int *pi = &(int&)d;
     *pd = 2;
     assert (*pd == 2);

The dynatype program is an example of a dynamic type, a type
which can hold and allow users to manipulate values of any
arbitrary type, so we need to consider the impact of changes
to the dynatype template on user code as if the class were
a general purpose library component. It would be unfortunate
to remove useful functionality just to work around bugs in
a single broken compiler.

I appreciate your effort to get the example to compile with
MSVC but if we can't come up with a portable workaround maybe
we need to acknowledge that the compiler is simply too broken
to compile the full example and move on.

Btw., I tried to get the test case you submitted to Microsoft
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=266262
to work and changing class test like this did it:

     struct test {
         template <class T> operator T& ();
         template <class T> operator const T& () const;
     };

Does it work in the full example?

Martin

> 
> Modified:
>     incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp
> 
> Modified: incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp?view=diff&rev=541635&r1=541634&r2=541635
> ==============================================================================
> --- incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp (original)
> +++ incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp Fri May 25 06:13:16 2007
> @@ -88,20 +88,13 @@
>          (this->*p_remove)();
>      }
>  
> -    // retrieve a reference to the concrete type from an instance of
> +    // retrieve a value of the concrete type from an instance of
>      // dynatype throws std::bad_cast if the types don't match exactly
>      template <class T>
> -    operator T& () {
> +    operator T () const {
>          if (map<T>::get ().end () == map<T>::get ().find (this))
>              throw std::bad_cast ();
>          return map<T>::get () [this];
> -    }
> -
> -    // retrieve a value of the concrete type from an instance of
> -    // dynatype throws std::bad_cast if the types don't match exactly
> -    template <class T>
> -    operator T () const {
> -        return static_cast<T&> (*const_cast<dynatype*>(this));
>      }
>  
>      // assign a value of any type to an instance of dynatype
> 
>