www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4606] New: access modifier causes failure to find stack pointer for template delegate

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

           Summary: access modifier causes failure to find stack pointer
                    for template delegate
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andy aligature.com


--- Comment #0 from andy aligature.com 2010-08-09 09:40:36 PDT ---
I encountered a problem while trying to change the less template parameter of
the setIntersection function in std.algorithm.  I finally distilled the problem
down to a simple example.

<code>
#!/usr/bin/env rdmd

import std.stdio;

struct Test(alias less)
{
public:
   void doit()
   {
      less(1, 2);
   }
}

void main()
{
   int x = 5;
   auto f = delegate bool(int a, int b){ writefln("%s %s %s", x, a, b); return
a < b; };

   auto d = Test!(f)();
   d.doit();
}
</code>

In this case, I should see output of "5 1 2", but instead I get a runtime
error:

./test.d(10): Error: function test.main.Test!(f).Test.doit cannot access frame
of function main
./test.d(19): Error: template instance test.main.Test!(f) error instantiating

If I remove the unneeded "public:" access modifier, the test works as expected.
 I'm using dmd v2.047 for Mac OS X downloaded from digitalmars.com.

This seems related to the post from Andrei to the d-announce mailing list back
in 07-Mar-2009
(http://www.mail-archive.com/digitalmars-d-announce puremagic.com/msg01332.html).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 09 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4606


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |yebblies gmail.com


--- Comment #1 from yebblies <yebblies gmail.com> 2011-07-10 18:06:08 EST ---
The problem is that when trying to decide if a struct is nested or not,
StructDeclaration::semantic only checks top-level symbols for functions.  It
should check inside nested symbols as well.

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