Thread overview
[Issue 6571] New: typedefs ignore const, shared, immutable etc modifiers when implicitly converting
Aug 29, 2011
yebblies
Aug 29, 2011
Iain Buclaw
Aug 29, 2011
Iain Buclaw
Aug 29, 2011
yebblies
Aug 31, 2011
Iain Buclaw
Sep 01, 2011
yebblies
Dec 30, 2011
Trass3r
Jan 21, 2012
Walter Bright
Jan 21, 2012
Walter Bright
August 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6571

           Summary: typedefs ignore const, shared, immutable etc modifiers
                    when implicitly converting
           Product: D
           Version: D1
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: yebblies@gmail.com


--- Comment #0 from yebblies <yebblies@gmail.com> 2011-08-30 01:45:15 EST ---
The following compiles without error on dmd2.055 head, although it includes
casting shared(void*) to void* and const(void*) to void*.  alias doesn't not
have the same problems.

void main()
{
    typedef void* A;
    void AA(A a) {}
    shared A a;
    const A b;
    AA(a);
    AA(b);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6571


Iain Buclaw <ibuclaw@ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@ubuntu.com


--- Comment #1 from Iain Buclaw <ibuclaw@ubuntu.com> 2011-08-29 09:38:19 PDT ---
I think this should sort it:


 MATCH TypeTypedef::constConv(Type *to)
 {
     if (equals(to))
         return MATCHexact;
-    if (ty == to->ty && sym == ((TypeTypedef *)to)->sym)
-        return sym->basetype->implicitConvTo(((TypeTypedef
*)to)->sym->basetype);
+    if (ty == to->ty && sym == ((TypeTypedef *)to)->sym &&
+        MODimplicitConv(mod, to->mod))
+        return MATCHconst;
     return MATCHnomatch;
 }



Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6571



--- Comment #2 from Iain Buclaw <ibuclaw@ubuntu.com> 2011-08-29 09:49:39 PDT ---
Patch breaks std.encoding:

std/encoding.d:373: Error: cannot implicitly convert expression (s[0u]) of type
const(AsciiChar) to AsciiChar
std/encoding.d:374: Error: cannot implicitly convert expression (s[0u]) of type
const(AsciiChar) to AsciiChar
std/encoding.d:380: Error: cannot implicitly convert expression (s[__dollar -
1u]) of type const(AsciiChar) to AsciiChar
std/encoding.d:381: Error: cannot implicitly convert expression (s[__dollar -
1u]) of type const(AsciiChar) to AsciiChar


Other than that, it is all good to go. :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6571



--- Comment #3 from yebblies <yebblies@gmail.com> 2011-08-30 04:08:03 EST ---
It should break std.windows.registry too, that's where I found it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 31, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6571



--- Comment #4 from Iain Buclaw <ibuclaw@ubuntu.com> 2011-08-31 15:44:04 PDT ---
I don't have windows so I can't test that. ;)

Everything is fine on the *nix side of things. For std.encoding, just replace the three 'typedef ubyte' with 'alias ubyte xxx'

Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6571



--- Comment #5 from yebblies <yebblies@gmail.com> 2011-09-01 15:22:20 EST ---
(In reply to comment #4)
> I don't have windows so I can't test that. ;)
> 

Since phobos and druntime don't use typedef any more, there should be no reliance on this bug any more.  Would you like to make a pull request?

> Everything is fine on the *nix side of things. For std.encoding, just replace the three 'typedef ubyte' with 'alias ubyte xxx'

This didn't work for me for some reason, I think the module relies on them being distinct types.  Using enums instead solved the problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 30, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6571


Trass3r <mrmocool@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool@gmx.de


--- Comment #6 from Trass3r <mrmocool@gmx.de> 2011-12-30 06:47:54 PST ---
A related issue is if const is part of the typedef.

typedef const(void*) type;
void bar(void* a) {}
void main()
{
    type a;
    bar(&a);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6571


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
            Version|D1                          |D2


--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> 2012-01-20 23:38:39 PST ---
First off, this is a D2, not a D1 issue. D

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6571


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> 2012-01-20 23:39:39 PST ---
... continued

D1 does not have shared/const, etc.

Secondly, typedefs are deprecated in D2. So this is "wontfix".

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