Thread overview
[Issue 2257] New: Template value parameters behave like alias parameters
Jul 31, 2008
d-bugmail
Oct 13, 2008
d-bugmail
Oct 13, 2009
Rob Jacques
Nov 07, 2009
Rob Jacques
Dec 01, 2010
Don
Dec 01, 2010
Don
Jan 30, 2012
yebblies
Feb 05, 2012
Stewart Gordon
Feb 05, 2013
Andrej Mitrovic
July 31, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2257

           Summary: Template value parameters behave like alias parameters
           Product: D
           Version: 2.017
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: samukha@voliacable.com


import std.stdio;

template Foo(string s)
{
  enum Foo = s; // changing enum to invariant fixes the issue.
}

void main()
{
  string a = "str";
  alias Foo!(a) b; // b is now an alias of a. Should be a compiler error
}


-- 

October 13, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2257





------- Comment #1 from samukha@voliacable.com  2008-10-13 00:32 -------
"compiler error" in the example was meant to be "compile error"


-- 

October 13, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2257


Rob Jacques <sandford@jhu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sandford@jhu.edu


--- Comment #2 from Rob Jacques <sandford@jhu.edu> 2009-10-13 10:21:10 PDT ---
This issue causes major issues with Nd-array and Small Vector implementations, as the incorrect type signatures play havoc with other templated functions. Here is another test case illustrating the problem:

import std.stdio;
struct Matrix(T,size_t D) {
    Matrix!(U,D) foo(U)(U v) { return Matrix!(U,D)(); }
}

void main() {
    real r;
    size_t d = 2;
    Matrix!(float,2) m;
    writeln(typeof( m.foo(r) ).stringof);            //writes Matrix(float,D)
    Matrix!(float,d) n;
    writeln(typeof( n ).stringof);                   //writes Matrix(float,d)
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 07, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2257



--- Comment #3 from Rob Jacques <sandford@jhu.edu> 2009-11-06 22:23:35 PST ---
(In reply to comment #2)
> This issue causes major issues with Nd-array and Small Vector implementations, as the incorrect type signatures play havoc with other templated functions. Here is another test case illustrating the problem:
> 
> import std.stdio;
> struct Matrix(T,size_t D) {
>     Matrix!(U,D) foo(U)(U v) { return Matrix!(U,D)(); }
> }
> 
> void main() {
>     real r;
>     size_t d = 2;
>     Matrix!(float,2) m;
>     writeln(typeof( m.foo(r) ).stringof);            //writes Matrix(float,D)
>     Matrix!(float,d) n;
>     writeln(typeof( n ).stringof);                   //writes Matrix(float,d)
> }

A Mitigation for the above example:
Matrix!(U,D+0) foo(U)(U v) { return Matrix!(U,D)(); }
changes "Matrix(float,D)" to "writes Matrix(float,2u)"
However, the original template type is still distinct: Matrix(float,2)

Also, it appears that even though D is unsigned, the template type is signed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2257


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-12-01 02:29:17 PST ---
*** Issue 4289 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2257


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-12-01 02:29:56 PST ---
Bug 2550 has the same root cause, I think.

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



--- Comment #6 from yebblies <yebblies@gmail.com> 2012-01-30 17:25:10 EST ---
*** Issue 2733 has been marked as a duplicate of this issue. ***

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


Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com


--- Comment #7 from Stewart Gordon <smjg@iname.com> 2012-02-05 14:56:56 PST ---
This might be related:
----------
struct DimensionedValue(Val, int Dim) {
    Val value;

    auto opMul(T)(T v) {
        return DimensionedValue!(typeof(value * T.init), Dim)(value * v);
    }
}

template isDimensionedValue(T : DimensionedValue!(V, D), V, int D) {
    enum bool isDimensionedValue = true;
}
template isDimensionedValue(T) {
    enum bool isDimensionedValue = false;
}

DimensionedValue!(int, 1) x;
//DimensionedValue!(double, 1) y;
pragma(msg, typeof(x * 2));
pragma(msg, isDimensionedValue!(typeof(x * 2)));
pragma(msg, typeof(x * 2.5));
pragma(msg, isDimensionedValue!(typeof(x * 2.5)));
----------
DimensionedValue!(int,1)
true
DimensionedValue!(double,Dim)
false
----------

Reinstating the declaration of y suppresses the bug.  As does using Dim + 0 in opMul.

Is this another manifestation of the same bug, or does it warrant a separate bug report?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=2257


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich@gmail.com
           Platform|x86                         |All
         Resolution|                            |WORKSFORME
         OS/Version|Windows                     |All


--- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-04 17:55:12 PST ---
Fixed since a long time ago, tested as far back as 2.053.

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