www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2085] New: CTFE fails if the function is forward referenced

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

           Summary: CTFE fails if the function is forward referenced
           Product: D
           Version: 1.029
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: samukha voliacable.com


Related to 2080.

----
const s = foo();
pragma(msg, s);

char[] foo()
{    
    return "Hi from foo";
}
----
Error: cannot evaluate ... you know :)

Worked around by placing s declaration and pragma after foo definition


-- 
May 09 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2085





------- Comment #1 from maxmo pochta.ru  2009-04-06 06:19 -------
another example
----
enum { a=b() }
int b(){ return 0; }
----


-- 
Apr 06 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2085


Sobirari Muhomori <maxmo pochta.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxmo pochta.ru




--- Comment #2 from Sobirari Muhomori <maxmo pochta.ru>  2009-05-18 03:43:27
PDT ---
This bug is hit regularly when porting C to D.
It's a shame that C macros don't suffer from this ordering bug :)
---
#define a b(0)
#define b(c) (c+1)
---

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


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |r.sagitario gmx.de


--- Comment #3 from Rainer Schuetze <r.sagitario gmx.de> 2010-03-27 05:53:06
PDT ---
Here's patch that invokes the semantic on the function if referenced.
Additioally, it needs to avoid duplicate semantic to be run later.

This patch also fixes #3499

Index: expression.c
===================================================================
--- expression.c    (revision 421)
+++ expression.c    (working copy)
   -2427,7 +2427,8   
     f = s->isFuncDeclaration();
     if (f)
     {    //printf("'%s' is a function\n", f->toChars());
-
+    if (!f->originalType && f->scope) // semantic not yet run
+        f->semantic(f->scope);
     if (!f->type->deco)
     {
         error("forward reference to %s", toChars());
Index: func.c
===================================================================
--- func.c    (revision 421)
+++ func.c    (working copy)
   -134,7 +134,7   
     parent = sc->parent;
     Dsymbol *parent = toParent();

-    if (semanticRun == PASSsemanticdone)
+    if (semanticRun >= PASSsemanticdone) // BUG 2085
     {
     if (!parent->isClassDeclaration())
         return;

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



--- Comment #4 from Don <clugdbug yahoo.com.au> 2010-04-10 11:31:33 PDT ---
Although bug 4075 appears similar to this one, the patch doesn't fix it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 10 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2085


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2010-05-10
11:45:39 PDT ---
changeset 478

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


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bearophile_hugs eml.cc
         Resolution|                            |FIXED


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