www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6197] New: std.traits.isImplicitlyConvertible returns some wrong results.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6197

           Summary: std.traits.isImplicitlyConvertible returns some wrong
                    results.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg gmail.com> 2011-06-23 04:01:22 PDT ---
pragma(msg, implicitlyConverts!(const(uint), ubyte));
should print 'false', but 'true'.

Cause of this bug:

Current implementation is here:
template isImplicitlyConvertible(From, To)
{
    enum bool isImplicitlyConvertible = is(typeof({
                        void fun(To) {}
                        From v;
                        fun(f);
                    }()));
}

When From=const(uint) and To=ubyte, it is rewites as

    enum bool isImplicitlyConvertible = is(typeof({
                        void fun(ubyte) {}
                        const(uint) v;
                        fun(f);
                    }()));

and function argument v is *optimized* to its initial value 0u and matches to
parameter type ubyte by literal conversion.

How to fix:
The variables its initializers are not visible does not cause optimization.
So rewrite as:

    enum bool isImplicitlyConvertible = is(typeof({
                      void fun(ref From v){
                        void gun(To) {}
                        gun(v);
                      }
                    }()));

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 23 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6197



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2011-06-23 04:06:35 PDT ---
(In reply to comment #0)
 pragma(msg, implicitlyConverts!(const(uint), ubyte));

Sorry, this is miss type. Following is correct. pragma(msg, isImplicitlyConvertible!(const(uint), ubyte)); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 23 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6197


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com


--- Comment #2 from SomeDude <lovelydear mailmetrash.com> 2012-04-24 11:36:13
PDT ---
With 2.059 Win32

PS E:\DigitalMars\dmd2\samples> dmd -c bug.d
false

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 24 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6197


Kenji Hara <k.hara.pg gmail.com> changed:

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


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2012-06-14 02:20:55 PDT ---
Already fixed in 2.060head.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2012