www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10708] New: Class members as template alias parameters not CTFE-able

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10708

           Summary: Class members as template alias parameters not
                    CTFE-able
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: johannespfau gmail.com


--- Comment #0 from Johannes Pfau <johannespfau gmail.com> 2013-07-23 23:56:33
PDT ---
Test case:
------------------------
class TestClass
{
    int a;
    this()
    {
        enum c = getAttribute!(TestClass.a);
    }
}

int getAttribute(alias target)()
{
    return 0;
}
------------------------
produces this error in DMD 2.063:
Error: value of 'this' is not known at compile time

This is annoying as you can use e.g. __traits(getAttributes, TestClass.a) but
you can not wrap this call into a template because of this bug.

A workaround as mentioned by Andrej Mitrovic is adding static to the
getAttribute template declaration.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 23 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10708



--- Comment #1 from Don <clugdbug yahoo.com.au> 2013-07-25 01:39:22 PDT ---
This isn't actually a CTFE issue. Something weird is happening here, maybe
related to UFCS.
The declaration of c is actually being transformed into:

enum c = this.getAttribute!(TestClass.a);

and that's the 'this' which CTFE is complaining about. Bizarrely, marking the
template as 'static' prevents that incorrect 'this' from being added.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2013