[Issue 24516] New: qualifiers lost when tupleof is aliased

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 21 04:16:39 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24516

          Issue ID: 24516
           Summary: qualifiers lost when tupleof is aliased
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: issues.dlang at jmdavisProg.com

When tupleof is used on a const type, the types of the resulting symbols are
const. However, if the result of tupleof is aliased (either directly within a
function or inside an eponymous template), then the constness is lost.

---
void main()
{
    import std.meta : AliasSeq;

    static struct S
    {
        int i;
        int* ptr;
        string str;
    }

    static assert(is(typeof(S.tupleof) == AliasSeq!(int, int*, string)));
    static assert(is(typeof(const(S).tupleof) == AliasSeq!(const int, const
int*, const string)));

    alias CS = const S;
    static assert(is(typeof(CS.tupleof) == AliasSeq!(const int, const int*,
const string)));

    alias Symbols = S.tupleof;
    alias ConstSymbols = CS.tupleof;

    static assert(is(typeof(Symbols) == AliasSeq!(int, int*, string)));

    // fails
    static assert(is(typeof(ConstSymbols) == AliasSeq!(const int, const int*,
const string)));

    static assert(is(typeof(FieldSymbols!S) == AliasSeq!(int, int*, string)));

    // fails
    static assert(is(typeof(FieldSymbols!(const S)) == AliasSeq!(const int,
const int*, const string)));
}

template FieldSymbols(T)
{
    alias FieldSymbols = T.tupleof;
}
---

The lines that are marked with // fails result in

---
test.d(22): Error: static assert:  `is((int, int*, string) == (const(int),
const(int*), const(string)))` is false
---

indicating that the constness was lost when the result of tupleof was aliased.

--


More information about the Digitalmars-d-bugs mailing list