September 22, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3339

           Summary: template "is not evaluatable at compile time" error
                    inconsistencies
           Product: D
           Version: 2.032
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: chadjoan@gmail.com


--- Comment #0 from Chad Joan <chadjoan@gmail.com> 2009-09-22 01:33:36 PDT ---
Version 1 of the program:
---------------------------------------
pure string wham(string str)
{
    return str;
}

template ouch(string val)
{
    mixin(`const bool ouch = `~wham(val)~`;`);
}

static assert( ouch!("true") );
static assert( !ouch!("false") );

void main(){}
---------------------------------------
This will compile just fine.

I'm actually not sure if it should or not.

By moving the wham function into the ouch template, the code will no longer compile; complaining about not being able to evaluate ouch at compile time. The changes make it look like so:
---------------------------------------
template ouch(string val)
{
    pure string wham(string str)
    {
        return str;
    }

    mixin(`const bool ouch = `~wham(val)~`;`);
}

static assert( ouch!("true") );
static assert( !ouch!("false") );

void main(){}
---------------------------------------
main2.d(11): Error: static assert  (ouch!("true")) is not evaluatable at
compile time


Another way to get the error is to store the result of wham into a constant and try to use it:
---------------------------------------
pure string wham(string str)
{
    return str;
}

template ouch(string val)
{
    const string str = wham(val);
    mixin(`const bool ouch = `~str~`;`);
    // Same goes for `enum str = wham(val);`
}

static assert( ouch!("true") );
static assert( !ouch!("false") );

void main(){}
---------------------------------------
main3.d(13): Error: static assert  (ouch!("true")) is not evaluatable at
compile time

Again, I'm not actually sure whether these examples should compile or not. However, they should all be equivalent, yet one case will compile and the other ones will not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3339


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug@yahoo.com.au
         Resolution|                            |INVALID


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-11-09 14:29:44 PST ---
The syntax in cases 2 and 3 is wrong. It should be
ouch!(true).ouch
because there is more than one member in the template.

When this is done, everything works correctly.

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