www.digitalmars.com         C & C++   DMDScript  

c++.beta - [bug] ambiguous type conversion with __int64

reply Gilles Depeyrot <gsd dolphin.fr> writes:
Hi,

The short C++ excerpt provided below causes DMC to bail out with:

     v3 = v1 + v2;
                 ^
int64.cpp(20) : Error: ambiguous type conversion
--- errorlevel 1

I compiled using the command line:

dmc -c -g -mn -WD -L/noi -L/nol int64.cpp

Any idea what might be causing this? The same code compiles fine using
MSVC or GCC.

Best regards,
Gilles


class INT64 {
public:
     __int64         mValue;
public:
     INT64();
     INT64(const INT64 &);
     INT64(__int64);
     // operators
     INT64 &operator =(const INT64 &);
     INT64 &operator =(__int64);
     operator __int64() const { return mValue; }
};

void main()
{
     INT64 v1(2);
     INT64 v2(4);
     INT64 v3;

     v3 = v1 + v2;
}
May 25 2006
parent reply "Matthew" <nowhere noaddress.co.us> writes:
Well, at a first glance, you should be providing addition operator (along 
with all the other arithmetic operators). Beyond that, you're going to want 
to do a lot of handling of integral conversions.

You might want to check out the stlsoft::sinteger64 class (in 
<stlsoft/64bit_integers.hpp>), from STLSoft (http://stlsoft.org/).

If you're interested, its implementation (and many of the issues surrounding 
implementing arithmetic user types) is described in Chapter 29 of Imperfect 
C++ (http://imperfectcplusplus.com/).

Enjoy!


"Gilles Depeyrot" <gsd dolphin.fr> wrote in message 
news:e53vpb$1tvs$1 digitaldaemon.com...
 Hi,

 The short C++ excerpt provided below causes DMC to bail out with:

     v3 = v1 + v2;
                 ^
 int64.cpp(20) : Error: ambiguous type conversion
 --- errorlevel 1

 I compiled using the command line:

 dmc -c -g -mn -WD -L/noi -L/nol int64.cpp

 Any idea what might be causing this? The same code compiles fine using
 MSVC or GCC.

 Best regards,
 Gilles


 class INT64 {
 public:
     __int64         mValue;
 public:
     INT64();
     INT64(const INT64 &);
     INT64(__int64);
     // operators
     INT64 &operator =(const INT64 &);
     INT64 &operator =(__int64);
     operator __int64() const { return mValue; }
 };

 void main()
 {
     INT64 v1(2);
     INT64 v2(4);
     INT64 v3;

     v3 = v1 + v2;
 } 
May 25 2006
parent reply Gilles Depeyrot <gsd dolphin.fr> writes:
Hi,

I am quite aware that the code is not ideal and not even complete since 
I extracted it from a much larger code base that works with other compilers.

My aim was to understand why DMC doesn't compile my code whereas MSVC 
and GCC both do. AS far as I can tell, the type conversion is not 
ambiguous as is.

Gilles

Matthew wrote:
 Well, at a first glance, you should be providing addition operator (along 
 with all the other arithmetic operators). Beyond that, you're going to want 
 to do a lot of handling of integral conversions.
 
 You might want to check out the stlsoft::sinteger64 class (in 
 <stlsoft/64bit_integers.hpp>), from STLSoft (http://stlsoft.org/).
 
 If you're interested, its implementation (and many of the issues surrounding 
 implementing arithmetic user types) is described in Chapter 29 of Imperfect 
 C++ (http://imperfectcplusplus.com/).
 
 Enjoy!
 
 
 "Gilles Depeyrot" <gsd dolphin.fr> wrote in message 
 news:e53vpb$1tvs$1 digitaldaemon.com...
 Hi,

 The short C++ excerpt provided below causes DMC to bail out with:

     v3 = v1 + v2;
                 ^
 int64.cpp(20) : Error: ambiguous type conversion
 --- errorlevel 1

 I compiled using the command line:

 dmc -c -g -mn -WD -L/noi -L/nol int64.cpp

 Any idea what might be causing this? The same code compiles fine using
 MSVC or GCC.

 Best regards,
 Gilles


 class INT64 {
 public:
     __int64         mValue;
 public:
     INT64();
     INT64(const INT64 &);
     INT64(__int64);
     // operators
     INT64 &operator =(const INT64 &);
     INT64 &operator =(__int64);
     operator __int64() const { return mValue; }
 };

 void main()
 {
     INT64 v1(2);
     INT64 v2(4);
     INT64 v3;

     v3 = v1 + v2;
 } 
May 30 2006
parent reply "Matthew" <nowhere noaddress.co.us> writes:
Ok. Sorry if I misunderstood.

Although I like the compiler, my experience is that DMC++ does experience a 
lot more "weirdies" than others. This is doubtless an artefact of its having 
a totally separate heritage: IIRC it derives from the first straight-through 
C++ compiler. (Walter's been around a while.)

90% of the time my approach to its problems is a pragmatic one: I just find 
workarounds. You'll find the knowledge of such dotted throughout the STLSoft 
(and other) libraries. When I am able to, I boil it down and submit a report 
to Walter, who, to his immense credit, generally manages to divine the 
problem and find the fix in a very short time. Unfortunately, when it cannot 
be boiled down, workarounds must suffice since Walter, understandably, 
refuses to try and work on undistilled (and potentially huge and enmeshed) 
problems. Since DMC++ is not my workaday C++ compiler, sometimes the 
workaround is simply to define a component as "#if defined(__DMC__) #error 
Not compatible with DMC++".

Given the apparent simplicity of the code that's causing the problem, I 
suspect a fix can be found. I again suggest you consult the implementation 
of stlsoft::sinteger64 for some ideas, since that component works correctly 
for many compilers, including DMC++.

HTH

Matthew


"Gilles Depeyrot" <gsd dolphin.fr> wrote in message 
news:e5gvdb$31ck$1 digitaldaemon.com...
 Hi,

 I am quite aware that the code is not ideal and not even complete since I 
 extracted it from a much larger code base that works with other compilers.

 My aim was to understand why DMC doesn't compile my code whereas MSVC and 
 GCC both do. AS far as I can tell, the type conversion is not ambiguous as 
 is.

 Gilles

 Matthew wrote:
 Well, at a first glance, you should be providing addition operator (along 
 with all the other arithmetic operators). Beyond that, you're going to 
 want to do a lot of handling of integral conversions.

 You might want to check out the stlsoft::sinteger64 class (in 
 <stlsoft/64bit_integers.hpp>), from STLSoft (http://stlsoft.org/).

 If you're interested, its implementation (and many of the issues 
 surrounding implementing arithmetic user types) is described in Chapter 
 29 of Imperfect C++ (http://imperfectcplusplus.com/).

 Enjoy!


 "Gilles Depeyrot" <gsd dolphin.fr> wrote in message 
 news:e53vpb$1tvs$1 digitaldaemon.com...
 Hi,

 The short C++ excerpt provided below causes DMC to bail out with:

     v3 = v1 + v2;
                 ^
 int64.cpp(20) : Error: ambiguous type conversion
 --- errorlevel 1

 I compiled using the command line:

 dmc -c -g -mn -WD -L/noi -L/nol int64.cpp

 Any idea what might be causing this? The same code compiles fine using
 MSVC or GCC.

 Best regards,
 Gilles


 class INT64 {
 public:
     __int64         mValue;
 public:
     INT64();
     INT64(const INT64 &);
     INT64(__int64);
     // operators
     INT64 &operator =(const INT64 &);
     INT64 &operator =(__int64);
     operator __int64() const { return mValue; }
 };

 void main()
 {
     INT64 v1(2);
     INT64 v2(4);
     INT64 v3;

     v3 = v1 + v2;
 }
May 30 2006
parent Gilles Depeyrot <gsd dolphin.fr> writes:
Hi Matthew,

I certainly agree with you but I hope my feedback will help improve DMC. 
Given Walter's reactivity fixing issues with small testcases, it 
certainly should ;-)

Gilles

Matthew wrote:
 Ok. Sorry if I misunderstood.
 
 Although I like the compiler, my experience is that DMC++ does experience a 
 lot more "weirdies" than others. This is doubtless an artefact of its having 
 a totally separate heritage: IIRC it derives from the first straight-through 
 C++ compiler. (Walter's been around a while.)
 
 90% of the time my approach to its problems is a pragmatic one: I just find 
 workarounds. You'll find the knowledge of such dotted throughout the STLSoft 
 (and other) libraries. When I am able to, I boil it down and submit a report 
 to Walter, who, to his immense credit, generally manages to divine the 
 problem and find the fix in a very short time. Unfortunately, when it cannot 
 be boiled down, workarounds must suffice since Walter, understandably, 
 refuses to try and work on undistilled (and potentially huge and enmeshed) 
 problems. Since DMC++ is not my workaday C++ compiler, sometimes the 
 workaround is simply to define a component as "#if defined(__DMC__) #error 
 Not compatible with DMC++".
 
 Given the apparent simplicity of the code that's causing the problem, I 
 suspect a fix can be found. I again suggest you consult the implementation 
 of stlsoft::sinteger64 for some ideas, since that component works correctly 
 for many compilers, including DMC++.
May 31 2006