2085 – CTFE fails if the function is forward referenced

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2085 - CTFE fails if the function is forward referenced
Summary: CTFE fails if the function is forward referenced
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
: 2513 (view as issue list)
Depends on:
Blocks: 340
Show dependency tree / graph
Reported: 2008年05月09日 07:02 UTC by Max Samukha
Modified: 2021年01月25日 12:56 UTC (History)
4 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2008年05月09日 07:02:42 UTC
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 anonymous4 2009年04月06日 06:19:11 UTC
another example
----
enum { a=b() }
int b(){ return 0; }
----
Comment 2 anonymous4 2009年05月18日 03:43:27 UTC
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 Rainer Schuetze 2010年03月27日 05:53:06 UTC
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 Don 2010年04月10日 11:31:33 UTC
Although bug 4075 appears similar to this one, the patch doesn't fix it.
Comment 5 Walter Bright 2010年05月10日 11:45:39 UTC
changeset 478
Comment 6 Don 2012年05月14日 08:23:28 UTC
*** Issue 2513 has been marked as a duplicate of this issue. ***
Comment 7 Dlang Bot 2021年01月25日 12:56:28 UTC
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 


AltStyle によって変換されたページ (->オリジナル) /