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]

Problem with conversion operator from template class >>Text und Anhang sindVIRENFREI !!<<


/* Hello,

  I have a problem with the compiler gcc version 3.2 20020927 (prerelease)
on Window XP.
     For details please see attachment out.log in mail.
  Compiling this file with
     g++ -w test.cpp
  results in
     test.cpp: In function `int main()':
  test.cpp:55: no match for `int * Wrapper<int>&' operator

     Compiling this with
     g++ -w -DNO_ERRORS test.cpp
     works.
  The define just adds an explicit cast and now the compiler can deduce how the "*" in line 63
     can be compiled. So I guess the compiler can only use conversion operators
     from template classes that have been instanciated at least once explicitly.

  Could you please tell me if I (once again) failed to understand the standard and explain
     the reasons and ramifications [what if different compilation units instantiate different
     possible conversions, will this ambuguity be detected ?] for this behaviour
  or if this is really a bug ?

  Regards
  Burkhard Neppert
  b.neppert@dr-staedtler.de
*/
#include <vector>
using namespace std;


template<class T>
struct Wrapper {
     Wrapper() : val()  {}
     Wrapper(T const & v) : val(v) {}

     operator T&() { return val; }
     operator T const&() const { return val; }
     Wrapper & operator=(T const & rhs) {
          val=rhs;
          return *this;
     }
     T val;
};


int main() {
     vector<Wrapper<int> > foo;

#if defined(NO_ERRORS)
     // If we just use this conversion from Wrapper<int> => int once explicitly
     // then the rest compiles OK
     (int)(*foo.begin());
#endif
     for(vector<Wrapper<int> >::iterator iter=foo.begin(); iter!=foo.end(); ++iter) {
          (*iter)=10*(*iter)+1;   // Depends on the explicit call of conversion from Wrapper<int> to int
     }

     return 0;
}
(See attached file: test.cpp)(See attached file: out.log)

Attachment: test.cpp
Description: Binary data

Attachment: out.log
Description: Binary data


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