[Issue 17439] New: invalid instantiation of function template can be executed by taking function pointer first

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri May 26 07:40:42 PDT 2017


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

          Issue ID: 17439
           Summary: invalid instantiation of function template can be
                    executed by taking function pointer first
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ag0aep6g at gmail.com

This is a spin-off from issue 17435.

This code should be rejected:

----
struct S { int field; }
template ft(alias a) { int f() { return a; } }

void main()
{
    /* ft!(S.field).f(); */ /* correctly rejected */
    alias fa = ft!(S.field).f; /* accepted */
    /* fa(); */ /* correctly rejected */
    int function() fptr = &fa; /* accepted */
    int i = fptr(); /* accepted */
}
----

At least one of the "accepted" lines should be rejected.

When ft or f are marked as `static`, the instantiation of ft (the first
"accepted" line) gets rejected. Adding `static` like that should not have any
effect. The template and the resulting function are already at module level.

--


More information about the Digitalmars-d-bugs mailing list