Another verify_cgraph problem

Johannes Pfau nospam at example.com
Sat Jan 12 02:57:10 PST 2013


I reduced another verify_cgraph issue (again, only shown on 4.7 and
with --enable-checking=yes).

This is the example:
---------------
void parseJSON()(char val)
{
    void error()
    {
    }

    void getChar()() //Scope not set to parseJSON
    {
        error();
    }

    void parseString()
    {
        getChar();
    }
}

void main()
{
    parseJSON('n');
}
---------------

If getChar is a template, it's scope is not set to parseJSON. If it's a
function the scope is set and everything works.

A short printf log for the failing case looks like this:
---------------
function  json.parseJSON!().parseJSON
1716 Calling error->toObjFile
function  json.parseJSON!().parseJSON.error
function end  json.parseJSON!().parseJSON.error
1716 Calling getChar()->toObjFile
1716 Calling parseString->toObjFile
function  json.parseJSON!().parseJSON.parseString
function end  json.parseJSON!().parseJSON.parseString
function end  json.parseJSON!().parseJSON
function  json.parseJSON!().parseJSON.getChar!().getChar
function end  json.parseJSON!().parseJSON.getChar!().getChar
---------------

So getChar's toObjfile isn't called at the correct time. If getChar is
a function, it's toObjfile is called after this line:
1716 Calling getChar()->toObjFile

This call is happening in d-glue.cc DeclarationExp::toElem,
declaration->toObjFile (false);

A template's toObjFile does nothing, but all my naive attempts to call
e.g.
declaration->isTemplateDeclaration()>onemember->isDeclaration()->toObjFile(false)
fail with a strange error. So do you have any idea how to fix this?

BTW: Other combinations of templates in functions are affected as well:
----------
void parseJSON()(char val)
{
    void error()
    {
    }
    
    struct S() //Scope not set to parseJSON
    {
        void getChar()
        {
            error();
        }
    }


    void parseString()
    {
        S!() s;
        s.getChar();
    }
}

void main()
{
    parseJSON('n');
}
-------

I'll have to recheck the test case from last week, maybe it's also
scope related.


More information about the D.gnu mailing list