Jump to page: 1 2
Thread overview
[Issue 3467] New: Non-int integral template parameters not correctly propagated
Nov 02, 2009
Simen Kjaeraas
Oct 14, 2011
Kenji Hara
Oct 14, 2011
Kenji Hara
Nov 20, 2011
Walter Bright
Nov 20, 2011
Jonathan M Davis
Nov 24, 2011
Kenji Hara
Nov 29, 2011
Kenji Hara
Dec 01, 2011
Kenji Hara
Dec 10, 2011
klickverbot
Dec 11, 2011
Walter Bright
Dec 11, 2011
Walter Bright
Apr 25, 2012
Kenji Hara
Oct 30, 2012
Denis Shelomovskij
November 02, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3467

           Summary: Non-int integral template parameters not correctly
                    propagated
           Product: D
           Version: 2.035
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: simen.kjaras@gmail.com


--- Comment #0 from Simen Kjaeraas <simen.kjaras@gmail.com> 2009-11-02 02:56:38 PST ---
The below code snippet fails to compile on DMD 2.035:

Error: cannot implicitly convert expression (baz.barof type foo!(n) to foo!(4)

Now change uint to int, and everything works perfectly. This might have to do with literal types ( 4 is an int, not a uint, ulong, byte, or whatever ).

struct foo( uint n ) {
    foo!( n ) bar( ) {
        typeof( return ) result;
        return result;
    }
}

void main( ) {
    foo!( 4 ) baz;
    baz = baz.bar;// FAIL
}

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


bearophile_hugs@eml.cc changed:

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


--- Comment #1 from bearophile_hugs@eml.cc 2010-09-25 16:29:51 PDT ---
The bug is present in dmd 2.049 still:


struct Vec(size_t N) {
    void opBinary(string op:"~", size_t M)(Vec!M) {}
}
void main() {
    Vec!2 a1;
    Vec!3 a2;
    a1 ~ a2; // line 7, Error
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3467


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg@gmail.com


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-14 01:49:12 PDT ---
*** Issue 6806 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: -------
October 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3467


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
           Platform|Other                       |All
            Version|2.035                       |D1 & D2
         OS/Version|Windows                     |All


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-14 01:51:11 PDT ---
From bug 6806, this is D1 & D2 issue.

And D2 patch: https://github.com/D-Programming-Language/dmd/pull/449

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |INVALID


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2011-11-19 23:26:17 PST ---
I believe this is not a bug. The type of a template is based on what its argument types are, not its parameter types. Hence,

  foo!3

is always a different type from:

  foo!3u

even if foo is defined to take an int parameter.

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


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #5 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-11-19 23:39:12 PST ---
Why? I understand instantiating a different template with different arguments when the type itself is the argument. But when you've typed the argument, it's essentially the same as passing an argument to a function, only it's a template argument instead of a function argument.

In this case, the template says that it takes a uint. I would expect that it then would instatiated based on the _value_ of the argument, not its _type_. It already _has_ a type - uint. Making foo!3 and foo!3u be different is just plain confusing because they're being given the exact same value.

What value is there in having foo!3 and foo!3u be different? What does it add? I don't understand how the _type_ of the argument could matter when the type is already defined by the template and it's the value that changes between instantiations.

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


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


--- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> 2011-11-23 16:27:10 PST ---
(In reply to comment #4)
> I believe this is not a bug. The type of a template is based on what its argument types are, not its parameter types. Hence,
> 
>   foo!3
> 
> is always a different type from:
> 
>   foo!3u
> 
> even if foo is defined to take an int parameter.

The issue is that the foo template with signed integer makes incorrect instantiation internally.

There are two solutions:
1. Makes that instantiation invalid.
2. Promote signed integer template value parameter into unsigned.

My patch implements #2, and I believe that is correct.
Because non-suffix integer literal can implicitly convertible to unsigned.

And, my patch doesn't break existing code around template overloading. Following code still valid.

template Foo(int n){ enum Foo = 1; }
template Foo(uint n){ enum Foo = 2; }
static assert(Foo!10 == 1);
static assert(Foo!10u == 2);

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


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |komadori@gekkou.co.uk


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2011-11-28 16:59:59 PST ---
*** Issue 3210 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, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3467



--- Comment #8 from Kenji Hara <k.hara.pg@gmail.com> 2011-12-01 13:51:15 PST ---
Updated pull/449 to fix bug2550, they are almost same issues.

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


klickverbot <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@klickverbot.at


--- Comment #9 from klickverbot <code@klickverbot.at> 2011-12-10 05:23:02 PST ---
(In reply to comment #6)
> There are two solutions:
> 1. Makes that instantiation invalid.
> 2. Promote signed integer template value parameter into unsigned.
> 
> My patch implements #2, and I believe that is correct.
> Because non-suffix integer literal can implicitly convertible to unsigned.
> 
> And, my patch doesn't break existing code around template overloading.

I agree. For an integer _value_ (and this is what we are talking about here), distinguishing between 3 and 3u just makes no sense.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2