D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3743 - Forward reference problem with static if statements
Summary: Forward reference problem with static if statements
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-26 13:31 UTC by Adam Chrapkowski
Modified: 2024-12-13 17:51 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Adam Chrapkowski 2010-01-26 13:31:37 UTC
Forward reference fails when declaration is inside static if statement.

example:
//------------------------------------------------
const FOO_VER = 2;

static if(FOO_VER >= 2) // If Bar is defined
struct Bar {            // Foo should be defined too.
  Foo foo;
}

static if(FOO_VER >= 1)
struct Foo {
}
//------------------------------------------------

error: identifier 'Foo' is not defined 
error: 'Foo' is used as a type
error: variable 'main.Bar.foo' voids have no value

The problem occurs for structures and classes, but not for functions:

The following work correctly:
//------------------------------------------------
static if(FOO_VER >= 2)
class Bar {
  this(){ func(); };
}

static if(FOO_VER >= 1)
void func(){ }
//------------------------------------------------
static if(FOO_VER >= 2)
void func(){ Foo foo; }

static if(FOO_VER >= 1)
struct Foo {
}
Comment 1 Adam Wilson 2014-05-22 03:21:35 UTC
Updating this bug. Note that this effects Aurora Graphics.

The following will produce an 'undefined identifier' error in struct DWRITE_GLYPH_RUN on IDWriteFontFace

static if(DX110)
{
public struct DWRITE_GLYPH_RUN {
	IDWriteFontFace fontFace; //Error: Undefined Identifier
	//...
}
}
static if(DX111) { //...}
static if(DX112) { //...}
 
static if(DX110)
{
public interface IDWriteFontFace : IUnknown
{
	HRESULT GetDesignGlyphMetrics(const(uint*) Indices, uint Count, DWRITE_GLYPH_METRICS*
	//...
}
}
static if(DX111) { //...}
static if(DX112) { //...}
Comment 2 Joakim 2015-05-01 07:50:02 UTC
I think I ran into this issue when I tried to import core.sys.posix.sys.types.off_t in core.stdc.stdio, for use in the fpos_t definition on linux.  Commenting out the "static if" block around off_t fixed the issue, so it's definitely related to "static if" somehow.
Comment 3 dlangBugzillaToGithub 2024-12-13 17:51:18 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18151

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB