www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 923] New: No constant folding for template value default arguments

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

           Summary: No constant folding for template value default arguments
           Product: D
           Version: 1.004
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au


Error: expression 1 + 2 is not a valid template value argument
----------

void a(int b = 1+2)(){};

void main() {
    a!(1+2)();  // OK
    a();        // fails
}


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






workround: "a!()()" instead of "a()"

Added to DStress as
http://dstress.kuehne.cn/run/t/template_58_A.d
http://dstress.kuehne.cn/run/t/template_58_B.d
http://dstress.kuehne.cn/run/t/template_58_C.d
http://dstress.kuehne.cn/run/t/template_58_D.d
http://dstress.kuehne.cn/run/t/template_58_E.d


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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Summary|No constant folding for     |No constant folding for
                   |template value default      |template value default
                   |arguments                   |arguments, D1 only





This has already been fixed in D2. Here's the patch for D1.046. It's trivial.

Index: template.c
===================================================================
--- template.c    (revision 192)
+++ template.c    (working copy)
   -3951,6 +3951,7   
     {   sinteger_t v;
         real_t r;

+        ea = ea->optimize(WANTvalue | WANTinterpret);
         if (ea->op == TOKvar)
         {
         sa = ((VarExp *)ea)->var;

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


Don <clugdbug yahoo.com.au> changed:

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



Fixed DMD1.050.

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