www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2323] New: Internal error: taking address of a method of a temporary struct

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

           Summary: Internal error: taking address of a method of a
                    temporary struct
           Product: D
           Version: 2.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: snake.scaly gmail.com


Compiler reports an internal error if an address of a temporary struct's method
is taken:

---- begin test.d
void main()
{
    struct A {
        void foo() {}
        static A opCall() {A a; return a;}
    }
    void delegate() x = &A().foo;
}
---- end test.d

dmd test.d
Internal error: ..\ztc\cgcs.c 358 Workaround is to use an explicit stack variable for A(): auto y = A(); void delegate() x = &y.foo; compiles and works correctly. --
Aug 30 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2323


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, wrong-code
            Version|2.018                       |1.040





This bug also applies to D1. And it silently generates bad code if compiled
with -O. Reduced test case:
----
struct A {
    void foo() {}
}
A bar() {A a; return a;}
void main() {
    void delegate() x = &bar().foo;
}
---
Root cause: should not be able to make a delegate from something which isn't an
lvalue (just as you can't take address of a function return).

PATCH: add one line in expression.c, DelegateExp::semantic(Scope *sc)

    if (func->needThis())
        e1 = getRightThis(loc, sc, ad, e1, func);
+         e1->toLvalue(sc, e1);   // add this line
   }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2323






22:27:23 PDT ---
Sergey is right, and the fix is to create a temp on the stack, copy the struct
in, and take the address of that. One line fix in e2ir.c.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 22 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2323


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





02:46:38 PDT ---
Fixed dmd 1.046 and 2.031

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