Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 35 - Potentially wrong code with template alias parameters and nested functions
Summary: Potentially wrong code with template alias parameters and nested functions
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: All All
: --- major
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2013-01-12 18:17 CET by Johannes Pfau
Modified: 2013-03-01 17:21 CET (History)
1 user (show)

See Also:


Attachments
test case 1 (336 bytes, text/x-dsrc)
2013-01-12 18:17 CET, Johannes Pfau
Details
test case 2 (342 bytes, text/x-dsrc)
2013-01-12 18:17 CET, Johannes Pfau
Details
Simple patch (2.24 KB, patch)
2013-01-12 18:18 CET, Johannes Pfau
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Pfau 2013-01-12 18:17:10 CET
Created attachment 24 [details]
test case 1

Test case 1 and 2 basically show the same problem: If we have a template with access to an alias parameter, that alias parameter can be a nested function. So the template and therefore all functions in it have access to the nested function which essentially means those functions have to be treated as if they were nested as well. We currently mark those functions as TREE_PUBLIC which fails a verify check in gcc-4.7 when compiled with --enable-checking.

Basic example: (Pseudo-Code)
-------
void a()()
{
    int var;
    void b()
    {
        var = 0;
    }
    
    Test!b();
}

struct Test(alias t)
{
    void abc() //Marked as public, although calls nested function b
    {
        t();
    }
}
-------

Test case 2 shows that we also have to check recursively for parent templates. I'm not sure if this could also somehow affect templates instantiated with nested classes?

It seems the frontends hasNestedArgs and isnested members in TemplateDeclaration could be used to check for this. Those frontend functions don't correctly detect the second test case though:
http://d.puremagic.com/issues/show_bug.cgi?id=9292

Patch 1 shows how the frontend checking code could be used.
Comment 1 Johannes Pfau 2013-01-12 18:17:40 CET
Created attachment 25 [details]
test case 2
Comment 2 Johannes Pfau 2013-01-12 18:18:21 CET
Created attachment 26 [details]
Simple patch
Comment 3 Iain Buclaw 2013-01-12 18:23:58 CET
Looks fine to me, though the whitespace looks a bit off. :)
Comment 4 Johannes Pfau 2013-01-12 18:29:07 CET
Yes, the patch was only a quick test, it's not ready for merging. It's a little bit annoying that it can't detect complicated cases as the hasNestedArgs check in the frontend doesn't detect those properly...