Thread overview
[Issue 3567] std.traits: Unqual doesn't handle arrays well
Jun 18, 2018
FeepingCreature
Jul 12, 2018
Timoses
[Issue 3567] std.traits: Unqual strips qualifiers on structs with references that would break const/immutable.
Jul 12, 2018
Timoses
Jul 12, 2018
Timoses
Dec 12, 2019
berni44
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=3567

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|2.036                       |D2

--
June 18, 2018
https://issues.dlang.org/show_bug.cgi?id=3567

FeepingCreature <default_357-line@yahoo.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |default_357-line@yahoo.de
         Resolution|INVALID                     |---

--- Comment #3 from FeepingCreature <default_357-line@yahoo.de> ---
This bug needs a second look.

Consider this code:

struct S
{
  int* ipointer;
}

pragma(msg, (Unqual!(const S)).stringof);

As can be seen, Unqual has just deeply stripped const, not shallowly.

Either Unqual must be made to error when passed a const struct with reference, or Unqual must leave const(int[]) as int[].

The current state is broken.

--
June 18, 2018
https://issues.dlang.org/show_bug.cgi?id=3567

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe
                 CC|                            |schveiguy@yahoo.com
           Hardware|Other                       |All
                 OS|Linux                       |All
           Severity|normal                      |major

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
This is likely going to be disruptive to fix, so many things use Unqual. But nonetheless, it's an important bug.

--
July 12, 2018
https://issues.dlang.org/show_bug.cgi?id=3567

Timoses <timosesu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timosesu@gmail.com

--- Comment #5 from Timoses <timosesu@gmail.com> ---
The fact the Unqual only "shallowly" unqualifies a type can be pretty annoying when dealing with templates and inout functions.


struct S
{
    int[] vals;
}

template Temp(T)
{
    class Temp
    {
        T t;

        this(T t)
        { this.t = t; }

        auto get() inout
        {
            static if (is(T == S))
            {
                import std.traits : Unqual;
                alias tType = Unqual!(typeof(t.vals));
                pragma(msg, tType); // inout(int)[]
                return new inout Temp!tType(t.vals); // ERROR: Can't create
class Temp!(inout(int)[])
            }
        }
    }
}

unittest
{
    auto t = Temp!S;
    t.get();
}

Error: variable `onlineapp.Temp!(inout(int)[]).Temp.t` only parameters or stack
based variables can be inout
Error: template instance `onlineapp.Temp!(inout(int)[])` error instantiating


In this case a complete stripping of qualifiers is required!

Related discussion: https://forum.dlang.org/post/enwkjtdqivjldqpzzqrw@forum.dlang.org

--
July 12, 2018
https://issues.dlang.org/show_bug.cgi?id=3567

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|std.traits: Unqual doesn't  |std.traits: Unqual strips
                   |handle arrays well          |qualifiers on structs with
                   |                            |references that would break
                   |                            |const/immutable.

--- Comment #6 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Note, the bug here in FeepingCreature's case is that it strips more than it should. It is supposed to be safe to use Unqual.

So the expectation that Unqual should remove all mutability modifiers is incorrect.

I'm changing the title accordingly. Perhaps we should actually close this bug and open another, as the whole issue has really been flipped around?

--
July 12, 2018
https://issues.dlang.org/show_bug.cgi?id=3567

--- Comment #7 from Timoses <timosesu@gmail.com> ---
(In reply to Steven Schveighoffer from comment #6)
> I'm changing the title accordingly. Perhaps we should actually close this bug and open another, as the whole issue has really been flipped around?

Perhaps you're looking for this? https://issues.dlang.org/show_bug.cgi?id=8338

--
July 12, 2018
https://issues.dlang.org/show_bug.cgi?id=3567

--- Comment #8 from Timoses <timosesu@gmail.com> ---
(In reply to Steven Schveighoffer from comment #6)
> Note, the bug here in FeepingCreature's case is that it strips more than it should. It is supposed to be safe to use Unqual.
> 
> So the expectation that Unqual should remove all mutability modifiers is incorrect.

Tried to find examples where a complete stripping of qualifiers would break something. I guess here it is really required that it only strips the "head" qualifier:

https://github.com/dlang/phobos/blob/90a8fc387f25f9bdfc2c6ad4508da63c523be670/std/array.d#L1465

Though this is not the subject of this issue.. Should I perhaps create a new issue for https://issues.dlang.org/show_bug.cgi?id=3567#c5 ? Perhaps asking for a new trait?

--
July 12, 2018
https://issues.dlang.org/show_bug.cgi?id=3567

--- Comment #9 from Steven Schveighoffer <schveiguy@yahoo.com> ---
I think a trait "ForceUnqual" may be needed in some cases, but "Unqual" I have always expected to behave the way it does (except in the case of structs containing references, for which it should not strip anything).

Man, it would be nice to have a tail-modifier in D...

--
December 12, 2019
https://issues.dlang.org/show_bug.cgi?id=3567

berni44 <bugzilla@d-ecke.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang@jmdavisProg.co
                   |                            |m

--- Comment #10 from berni44 <bugzilla@d-ecke.de> ---
*** Issue 8338 has been marked as a duplicate of this issue. ***

--
December 01
https://issues.dlang.org/show_bug.cgi?id=3567

--- Comment #11 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9805

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--