www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18269] New: Inconsistent of delegate system attribute

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

          Issue ID: 18269
           Summary: Inconsistent of delegate  system attribute
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

Code:
------
void one(T)(T t, size_t ln = 0)
{
    pragma(msg, "one: ", T.stringof);
    two(t);
}

void two(T)(T t)
{
    pragma(msg, "two: ", T.stringof);
}

enum Seq(T...) = 0;
alias Bug = Seq!(void delegate());

void main()
{
    void func()  system { __gshared int x; ++x; throw new Exception(""); }
    one(&func);
}
------

Compiler command:
------
dmd -o- -c test.d
------

Compiler output:
------
one: void delegate()  system
two: void delegate()
------

Note the lack of  system on the second line.  Any of the following will cause
 system to appear on the second line:

- Removing the default parameter `ln` from the template function `one`.

- Commenting out the `alias Bug` line.

- Adding a default parameter `size_t ln = 0` to the template function `two`.


Curiously, if the default parameter `ln` is *moved* from `one` to `two`, the
output becomes:

-------
one: void delegate()
two: void delegate()
-------

which is even more strange, since the output now has *neither*  safe nor
 system.


Expected behaviour:
The output should at least be consistent, and certainly should not change
depending on whether the `alias Bug` line is there or not, since it has
absolutely nothing to do with the templates `one` and `two`.

--
Jan 19 2018