Bug 2085 – CTFE fails if the function is forward referenced

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-05-09T07:02:42Z
Last change time
2021-01-25T12:56:28Z
Keywords
patch, rejects-valid
Assigned to
No Owner
Creator
Max Samukha
Blocks
340

Comments

Comment #0 by samukha — 2008-05-09T07:02:42Z
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
Comment #1 by dfj1esp02 — 2009-04-06T06:19:11Z
another example ---- enum { a=b() } int b(){ return 0; } ----
Comment #2 by dfj1esp02 — 2009-05-18T03:43:27Z
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) ---
Comment #3 by r.sagitario — 2010-03-27T05:53:06Z
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;
Comment #4 by clugdbug — 2010-04-10T11:31:33Z
Although bug 4075 appears similar to this one, the patch doesn't fix it.
Comment #5 by bugzilla — 2010-05-10T11:45:39Z
changeset 478
Comment #6 by clugdbug — 2012-05-14T08:23:28Z
*** Issue 2513 has been marked as a duplicate of this issue. ***
Comment #7 by dlang-bot — 2021-01-25T12:56:28Z
dlang/dub pull request #2098 "Fix #2085: [visuald] spurious library project" was merged into master: - d2e8c03f89c52b6b57d12449acb87e1b67cd831b by Bastiaan Veelo: If no output is generated (TargetType.none) then don't generate a project configuration. This prevents VS from attempting to build a library with no name from no sources. Fixes #2085. - cf4a049bf8755fb988a1adf3adbf709dc025841b by Bastiaan Veelo: Test issue #2085. https://github.com/dlang/dub/pull/2098