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






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





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



PDT ---
Here's patch that invokes the semantic on the function if referenced.
Additioally, it needs to avoid duplicate semantic to be run later.



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




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



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 next 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
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2085


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |shro8822 vandals.uidaho.edu



*** Issue 2513 has been marked as a duplicate of this issue. ***

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