[Issue 10852] New: function wrongly inferred pure in embeded function with function cast

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 19 03:27:21 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10852

           Summary: function wrongly inferred pure in embeded function
                    with function cast
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2013-08-19 03:27:21 PDT ---
Given:
1. A template function
2. An embedded function
3. A function cast inside the embedded function

Given the above pre-requirements, the embedded function will (wrongly) see the
cast function as pure, and be wrongly inferred:

//----
//Impure function. Doesn't throw; not marked as such.
void impureFun()
{}

void nothrowFun()() nothrow
{
    void fun () nothrow
    {
        alias nothrow void function() StillImpure_t;
        (cast(StillImpure_t)&impureFun)();
    };
    fun();
}
void main() pure
{
    nothrowFun(); //PASSES! (shouldn't)
}
//----

Observations:
If the function is not templated, things are refused correctly. If there is no
embedded function, things are refused correctly.

Interesting observation:
If you try to explicitly mark the function as pure, then you *will* be shot
down:

//----
void nothrowFun()() nothrow
{
    void fun () nothrow pure
    {
        alias nothrow void function() StillImpure_t;
        (cast(StillImpure_t)&impureFun)(); //(here)
    };
    fun();
}
//----
Error: pure function 'main.nothrowFun!().nothrowFun.fun' cannot call impure
function pointer 'cast(void function() nothrow)& impureFun'

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


More information about the Digitalmars-d-bugs mailing list