Thread overview
[Issue 2550] New: template specialization not working because of "static if"?
Jan 01, 2009
d-bugmail
[Issue 2550] implicit conversions don't apply to template value parameter specialization
Sep 24, 2009
Don
Dec 01, 2010
Don
Dec 01, 2011
Kenji Hara
Dec 10, 2011
Kenji Hara
Dec 11, 2011
Walter Bright
Dec 11, 2011
Walter Bright
January 01, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2550

           Summary: template specialization not working because of "static
                    if"?
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: davidl@126.com


template pow10(long n)
{
        static if(n<0)
                const long pow10=0;
        else
                const long pow10=10*pow10!(n-1);
}

template pow10(long n:0)
{
        const long pow10=1;
}

static assert(pow10!(0) == 1);


-- 

September 24, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2550


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
            Summary|template specialization not |implicit conversions don't
                   |working because of "static  |apply to template value
                   |if"?                        |parameter specialization


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2009-09-24 07:15:54 PDT ---
Original title: 'template specialization not working because of "static if"?'

It's not because of 'static if'. This shows the same problem:

template pow10(long n){
   const long pow10=7;
}

template pow10(long n:0){
    const long pow10=1;
}

static assert(pow10!(0) == 1);

It will compile if you put
static assert(pow10!(0L) == 1);

It seems that the compiler requires template value specialisations have to exactly match both type and value, but I don't see that in the spec anywhere. Probably a bug. It's certainly pretty annoying.

-- 
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=2550



--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-12-01 02:30:22 PST ---
I believe bug 2257 is the same 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=2550


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2011-12-01 13:42:33 PST ---
D2 patch: https://github.com/D-Programming-Language/dmd/pull/449

This issue is almost same with bug3467.

-- 
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=2550


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@metalanguage.com


--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2011-12-10 12:08:27 PST ---
*** Issue 7090 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 11, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2550


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
           Severity|normal                      |enhancement


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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-12-10 16:38:21 PST ---
https://github.com/D-Programming-Language/dmd/commit/f8ad107800a2c9bf116779a49abe9945daf9d05f

Resolved for D2 only.

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