[Issue 8618] New: std.typecons.Typedef can't instead typedef keyword

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 4 08:04:51 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8618

           Summary: std.typecons.Typedef can't instead typedef keyword
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: cpunion at gmail.com


--- Comment #0 from Li Jie <cpunion at gmail.com> 2012-09-04 08:05:25 PDT ---
In old dmd, we can use typedef to create strong type. Now I found it
deprecated: http://dlang.org/deprecate.html#typedef . But it can't completely
instead typedef keyword.

The following code run failed, this happened in my project.

--- code
import std.typecons;    
import std.stdio;

void testString(S)() {
    S a = "a";
    S a1 = cast(string)"a".dup;
    S b = "b";

    assert(a1 == "a");
    assert(a == a1);

    bool[S] m;
    m[a] = true;

    bool* v;
    v = (a in m);
    assert(v);
    assert(*v);

    v = (b in m);
    assert(!v);

    v = (a1 in m);
    assert(v);                 // <----- failed line
    assert(*v);
}

void main() {
    alias Typedef!string MyString;

    testString!(string)();
    writeln("string test passed");

    testString!(MyString)();
    writeln("MyString test passed");
}
---

--- output
$ dmd testproxy.d 
$ ./testproxy 
string test passed
core.exception.AssertError at testproxy(30): Assertion failure
----------------
5   testproxy                           0x000000010e9a5ea6 _d_assertm + 38
6   testproxy                           0x000000010e99297b void
testproxy.__assert(int) + 23
7   testproxy                           0x000000010e992e45 void
testproxy.testString!(std.typecons.Typedef!(immutable(char)[],
null).Typedef).testString() + 441
8   testproxy                           0x000000010e992930 _Dmain + 36
9   testproxy                           0x000000010e9a6846 extern (C) int
rt.dmain2.main(int, char**).void runMain() + 34
10  testproxy                           0x000000010e9a61fd extern (C) int
rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 45
11  testproxy                           0x000000010e9a6890 extern (C) int
rt.dmain2.main(int, char**).void runAll() + 56
12  testproxy                           0x000000010e9a61fd extern (C) int
rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 45
13  testproxy                           0x000000010e9a6187 main + 235
14  libdyld.dylib                       0x00007fff8b17d7e1 start + 0
15  ???                                 0x0000000000000001 0x0 + 1
----------------
---

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


More information about the Digitalmars-d-bugs mailing list