www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14848] New: template alias on struct field without instance


          Issue ID: 14848
           Summary: template alias on struct field without instance
                    requires 'this'
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: remi.thebault outlook.com

template offsetof_member(alias member)
    size_t get() { return member.offsetof; }

struct S { int f }

int main (string[] args)
    auto i = offsetof_member!(S.f).get();
    return 0;

this code triggers:
Error: 'this' is only defined in non-static member functions, not main
despite no instance is involved.

Marking get with 'static' removes the compiler error

Jul 29 2015