www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3538] New: Default value of alias template parameter is instantiated only once.

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

           Summary: Default value of alias template parameter is
                    instantiated only once.
           Product: D
           Version: 2.036
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: e.insafutdinov gmail.com


--- Comment #0 from Eldar Insafutdinov <e.insafutdinov gmail.com> 2009-11-21
12:28:04 PST ---
template Boo(T) {}
struct Foo(T, alias V = Boo!T) { pragma(msg, V.stringof); }
alias Foo!double B;
alias Foo!int A;

outputs

Boo!(double)                                                        
Boo!(double)

while it should

Boo!(double)                                                        
Boo!(int)


Although it's a blocker for a design that I intend to use, I don't mark it as
such with hope that it'll get fixed, as it looks trivial to me.

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


Robert Clipsham <robert octarineparrot.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |robert octarineparrot.com


--- Comment #1 from Robert Clipsham <robert octarineparrot.com> 2010-04-23
20:50:46 BST ---
This is caused as default arguments to templates are only instantiated once,
which causes the Boo!T to always become whatever is instantiated first. The
patch below fixes this:
--- template.c       2010-03-18 18:58:06.000000000 +0000
+++ template.c  2010-04-23 20:49:54.000000000 +0100
   -2993,6 +2993,17   

 Object *TemplateAliasParameter::defaultArg(Loc loc, Scope *sc)
 {
+    Type *ta = isType(defaultAlias);
+    if (ta)
+    {
+       if (ta->ty == Tinstance)
+       {
+           // If the default arg is a template, instantiate for each type
+           Object *da = ta->syntaxCopy();
+           Object *o = aliasParameterSemantic(loc, sc, da);
+           return o;
+       }
+    }
     Object *o = aliasParameterSemantic(loc, sc, defaultAlias);
     return o;
 }

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


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2010-05-16
11:15:20 PDT ---
changelog 492

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