[Issue 18917] New: Default Value for Function-Type Template Value-Parameter Causes Conflicts in Instantiation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 30 09:36:17 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18917

          Issue ID: 18917
           Summary: Default Value for Function-Type Template
                    Value-Parameter Causes Conflicts in Instantiation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: madric at gmail.com

Consider the following code snippet of a template class that has 3 paramters,
the 3rd of which is a value-parameter with a function type and has a default
value.

```
final class BTree(
    ValueT,
    KeyT = ValueT,
    const(KeyT) function(ValueT) nothrow pure @nogc KeyF =
        function KeyT(ValueT a) { return a; }) {

  KeyT getKey(ValueT val) {
    return KeyF(val);
  }
}
```

When instantiating these templates, the first instantiation sets the value for
the function value-parameter, and subsequent instantiations fail due to
mismatching type.

Example:
```
void main()
{
    auto btree1 = new BTree!(char);
    auto btree2 = new BTree!(int);  // The error is on this line.
}
```

The error is:
```
onlineapp.d(17): Error: template instance `BTree!int` does not match template
declaration `BTree(ValueT, KeyT = ValueT, const(char) function(char) pure
nothrow @nogc KeyF = function KeyT(ValueT a)
{
return a;
}
)`
```

I believe that `BTree!(char)` and `BTree!(int)` should be recognized as
different types at compile-time that have separate and distinct default values
for the 3rd template-parameter.

--


More information about the Digitalmars-d-bugs mailing list