www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 918] New: Template order matter, version block change something with typedef, and another template bug.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918

           Summary: Template order matter, version block change something
                    with typedef, and another template bug.
           Product: D
           Version: 1.004
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: baryluk mpi.int.pl


import std.stdio;

typedef int num = 42;

version (A) {
        void pow(alias b)() {   writefln("full ", b); }
        void pow(num b)() {     writefln("num ", b); }
        void pow(int b)() {     writefln("int ", b); }
} else version (B) {
        void pow(num b)() {     writefln("num ", b); }
        void pow(alias b)() {   writefln("full ", b); }
        void pow(int b)() {     writefln("int ", b); }
} else version (C) {
        void pow(num b)() {     writefln("num ", b); }
        void pow(alias b)() {   writefln("full ", b); }
} else {
        static assert(false, "Provide version");
}

void main() {
        num wyk = 22;
        pow!(wyk);
}

/*
A: full 22

B: num 0  (why 0?, should be 22, eventually 42)

C:

./po.d(22): template instance pow!(wyk) matches more than one template
declaration, pow(num b) and pow(alias b)
./po.d(22): Error: import has no effect in expression (pow!(wyk))

Note: in A, B template "int" isn't used!

So probably 3 bugs.

When compiled without version block (leaving version B):

num 22

*/


-- 
Feb 01 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918


thomas-dloop kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
         OS/Version|Linux                       |All





http://digitalmars.com/d/template.html
 
 Determine which is more specialized is done the same way as the C++ partial 
ordering rules.

I'm unsure how C++'s rules would apply to the alias parameters and thus the 
specialization but I doubt that D shoud behave dependent on the template 
declaration order.


-- 
Apr 05 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918


baryluk smp.if.uj.edu.pl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|1.004                       |1.039





Just tested in newer compiler, same behaviour. (1.004, and 1.039)


-- 
Apr 02 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918


matti.niemenmaa+dbugzilla iki.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|1.039                       |1.004





-------
Please keep the version setting at the oldest, not the newest, known version
which exhibits the bug.


-- 
Apr 02 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918




21:25:29 PST ---
I recently retested this code in DMD 2.032:


a918.d:
-----
import std.stdio;

typedef int num = 42;

version (A) {
    void pow(alias b)() {     writefln("alias %d", b); }
    void pow(num b)() {    writefln("num %d", b); }
    void pow(int b)() {    writefln("int %d", b); }
} else version (B) {
    void pow(num b)() {    writefln("num %d", b); }
    void pow(alias b)() {     writefln("alias %d", b); }
    void pow(int b)() {    writefln("int %d", b); }
} else version (C) {
    void pow(num b)() {    writefln("num %d", b); }
    void pow(alias b)() {     writefln("alias %d", b); }
} else {
    static assert(false, "Provide version");
}


void main() {
    num wyk = 22;
writeln("calling num wyk=22?");
    pow!(wyk)();

writeln("calling int=4?");
    pow!(4)();

    uint x = 333;
writeln("calling alias=x=333?");
    pow!(x)();
}
-----

It looks it behaves much better than original bug report:

------
baryluk sredniczarny:/tmp$ dmd2 -version=A -w a918.d ; ./a918 
calling num wyk=22?
num -1077524476
calling int=4?
int 4
calling alias=x=333?
alias 333
baryluk sredniczarny:/tmp$ dmd2 -version=B -w a918.d ; ./a918 
calling num wyk=22?
num -1081977116
calling int=4?
int 4
calling alias=x=333?
alias 333
baryluk sredniczarny:/tmp$ dmd2 -version=C -w a918.d ; ./a918 
calling num wyk=22?
num -1076793804
calling int=4?
alias 4
calling alias=x=333?
alias 333
baryluk sredniczarny:/tmp$ 
-----

We have the same behaviour regardles of version. In version C int properly uses
"alias" template. Order of templates doesn't metter. Removing or leaving
"version" blocks, doesn't change behaviour.


But here we also see regression. num is not passed correctly. Even after
removing "version" blocks, and leaving only "B" part. It also doesn't print any
"0" or "42", or desired "22", but some random negative number.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918




20:44:41 PST ---
I tested it today on 2.039 and regression dissapered, now all 3 versions give
exactl the same correct answers:

$ dmd2 -version=B -w a918.d ; ./a918 
calling num wyk=22?
num 22
calling int=4?
int 4
calling alias=x=333?
alias 333
$

It can be closed now I think, but still I will want to test it in DMD 1.x.

Anyone knows what changes in compiler possibly made all this fixes, regression
and fixes? I can try historical version and check which have what behaviour.
I would not want to close error because it dissapered by random chance :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Summary|Template order matter,      |(D1 only): Template order
                   |version block change        |matter, version block
                   |something with typedef, and |change something with
                   |another template bug.       |typedef, and another
                   |                            |template bug.




 I tested it today on 2.039 and regression dissapered, now all 3 versions give
 exactl the same correct answers:
 
 $ dmd2 -version=B -w a918.d ; ./a918 
 calling num wyk=22?
 num 22
 calling int=4?
 int 4
 calling alias=x=333?
 alias 333
 $
 
 It can be closed now I think, but still I will want to test it in DMD 1.x.
 
 Anyone knows what changes in compiler possibly made all this fixes, regression
 and fixes? I can try historical version and check which have what behaviour.
 I would not want to close error because it dissapered by random chance :)
It was fixed in 2.033,2.034, or 2.035 (works in 2.035, fails in 2.032). Many compiler structural problems were fixed around that time, so we can expect many bugs to be fixed. It still fails in D1, so cannot be closed yet. But I've put 'D1 only' in the title. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 25 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=918


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|spec                        |
                 CC|                            |bugzilla digitalmars.com



11:45:02 PST ---
Not a spec issue.

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