Thread overview
[Issue 8338] New: Unqual doesn't work properly on arrays
Jul 03, 2012
Jonathan M Davis
Jul 03, 2012
Kenji Hara
Jul 03, 2012
Kenji Hara
Jul 03, 2012
Jonathan M Davis
Jul 03, 2012
Kenji Hara
July 03, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8338

           Summary: Unqual doesn't work properly on arrays
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: jmdavisProg@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-02 19:12:33 PDT ---
Take this bit of code

import std.stdio;
import std.traits;

void main()
{
    writeln(Unqual!(char[]).stringof);
    writeln(Unqual!(wchar[]).stringof);
    writeln(Unqual!(dchar[]).stringof);
    writeln(Unqual!(const char[]).stringof);
    writeln(Unqual!(const wchar[]).stringof);
    writeln(Unqual!(const dchar[]).stringof);
    writeln(Unqual!string.stringof);
    writeln(Unqual!wstring.stringof);
    writeln(Unqual!dstring.stringof);
    writeln();
    writeln(Unqual!(ubyte[]).stringof);
    writeln(Unqual!(short[]).stringof);
    writeln(Unqual!(uint[]).stringof);
    writeln(Unqual!(const ubyte[]).stringof);
    writeln(Unqual!(const short[]).stringof);
    writeln(Unqual!(const uint[]).stringof);
    writeln(Unqual!(immutable ubyte[]).stringof);
    writeln(Unqual!(immutable short[]).stringof);
    writeln(Unqual!(immutable uint[]).stringof);
}

It prints out

char[]
wchar[]
dchar[]
const(char)[]
const(wchar)[]
const(dchar)[]
string
immutable(wchar)[]
immutable(dchar)[]

ubyte[]
short[]
uint[]
const(ubyte)[]
const(short)[]
const(uint)[]
immutable(ubyte)[]
immutable(short)[]
immutable(uint)[]

None of those const or immutables should be there. The only changes between
this and not using Unqual at all is the const T[] are now const(T)[] and the
immutable T[] are now immutable(T)[]. And the immutable(T)[], are still
immutable(T)[]. The immutable on their elements aren't stripped.

Unqual specifically states that it removes _all_ qualifiers. It's clearly only removing them from the array itself and not the elements, so it's not removing all of the qualifiers.

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-07-02 19:40:39 PDT ---
(In reply to comment #0)
> Take this bit of code
> 
[snip]
> 
> None of those const or immutables should be there. The only changes between
> this and not using Unqual at all is the const T[] are now const(T)[] and the
> immutable T[] are now immutable(T)[]. And the immutable(T)[], are still
> immutable(T)[]. The immutable on their elements aren't stripped.
> 
> Unqual specifically states that it removes _all_ qualifiers. It's clearly only removing them from the array itself and not the elements, so it's not removing all of the qualifiers.

Yes. std.traits.Unqual removes the top qualifier of given type, not all ones. But, changing its implementation would break *maby* existing codes, so, instead, we should fix its documentation.

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



--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-07-02 19:41:54 PDT ---
> But, changing its implementation would break *maby* existing codes, so,

s/maby/many/

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



--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-02 20:03:22 PDT ---
Maybe. But I'm not completely convinced that it would break all that much code - particularly since I would have expected any code using Unqual to be written with the intention of stripping _all_ of the qualifiers (as the documentation says). If we don't make the change though, we need a new template similar to Unqual (FullUnqual? RecUnqual?) which really _does_ strip all of the qualifiers.

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



--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2012-07-02 21:01:13 PDT ---
(In reply to comment #3)
> Maybe. But I'm not completely convinced that it would break all that much code - particularly since I would have expected any code using Unqual to be written with the intention of stripping _all_ of the qualifiers (as the documentation says).

But, getting type stripped full qualifiers is much unsafe than just top.

  const string s = "Hello";   // const(immutable(char)[])
  auto mutable_s = cast(Unqual!(typeof(s)))s;  // ???

In many cases, current Unqual is used with unsafe casting, even if it is bad
idiom. Changing the implementation of Unqual will become such codes *more*
unsafe silently.
(As far as I know, Phobos doesn't have such bad using. I'm talking about the
user codes written by programmers don't know well about const/immutable type
system.)

And in (sadly) few cases that uses Unqual correct way, it will change codes
from safe to unsafe.

  Stripping top qualifier of array/string types:

https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1634

https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1705


> If we don't make the change though, we need a new template similar to Unqual (FullUnqual? RecUnqual?) which really _does_ strip all of the qualifiers.

Noqual?

Or, add new two templates, one removes just top qualifier, another does all qualifiers. I think this is the best way, but have no idea about their names...

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