www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17439] New: invalid instantiation of function template can be


          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 puremagic.com
          Reporter: ag0aep6g 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.

May 26 2017