www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17504] New: Passing templated varargs to array varargs base


          Issue ID: 17504
           Summary: Passing templated varargs to array varargs base class
                    constructor segfaults
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: nanayamae gmail.com

Created attachment 1649
  --> https://issues.dlang.org/attachment.cgi?id=1649&action=edit
Reduction of the segfault

I have a templated wrapper class (TC) that inherits from its template argument.
The base class's (BC) constructor arguments are unknown, therefore the
constructor of TC is templated with 
this(Args...)(MyType wrappedObj, Args args)
and calls its base constructor using args.
When the base constructor has varargs 
this(MyType[] objs...)
    _objs = objs;
and TC's templated constructor is called using varargs 
auto tc = new TC(wrappedObj, obj1, obj2); // segfaults
any attempt at accessing the objects in _objs by iterating (std.algorithm or
foreach) segfaults (see attachment). Calling _objs[0] and accessing its members
is ok.
A workaround is passing in an array instead of varargs, therefore marked as
auto tc = new TC(wrappedObj, [obj1, obj2]); // ok
The full code is in attachment.

(Please forgive me if I mixed up a bit of terminology.)

Jun 14 2017