D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4709 - ICE(mtype.c): undefined variable in const struct
Summary: ICE(mtype.c): undefined variable in const struct
Status: RESOLVED DUPLICATE of issue 4434
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2010-08-22 00:35 UTC by Heromyth
Modified: 2010-11-07 12:27 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 Heromyth 2010-08-22 00:35:47 UTC
The following code will lead DMD terminated abnormally. After getting rid of the "const" in "const struct SB_uint8", this termination problem is missing. 
===================
import std.stdio;

/*
struct D_Shift {
  ushort	symbol;
  ubyte		shift_kind;
  ubyte		op_assoc;
  int		op_priority;
  int		term_priority;
  int		action_index;
}
*/

// the bug is here
const struct SB_uint8 {
  D_Shift 		**shift;
  ubyte	*[2] scanner_block;
}

int main(string[] args)
{
    return 0;
}

/*
Z:\>dmd main.d
main.d(17): Error: identifier 'D_Shift' is not defined
main.d(17): Error: D_Shift is used as a type
main.d(20): Error: identifier 'D_Shift' is not defined
main.d(20): Error: D_Shift is used as a type
Assertion failure: 'tn->mod & MODimmutable || tn->mod & MODconst' on line 875 in
 file 'mtype.c'

abnormal program termination
*/
Comment 1 bearophile_hugs 2010-08-22 06:25:58 UTC
It's the undefined Bar inside a const struct that causes the problem:


const struct Foo {
    Bar* p;
}
void main() {}
Comment 2 Jeremy 2010-11-06 17:02:59 UTC
I get this same bug using 'alias const', eg:

alias int ITEMIDLIST_ABSOLUTE;
alias const ITEMIDLIST_ABSOLUTE *PCIDLIST_ABSOLUTE;

Gives the same compile error:
Assertion failure: 'tn->mod & MODimmutable || tn->mod & MODconst' on line 875 in file 'mtype.c'

This also happens if you use a struct:

struct ITEMIDLIST_ABSOLUTE
{
	int foo;
}
alias const ITEMIDLIST_ABSOLUTE *PCIDLIST_ABSOLUTE;

But *not* if you use a primitive type directly:

alias const int *PCIDLIST_ABSOLUTE;

Removing the const also avoids the error.
Comment 3 Don 2010-11-06 23:29:56 UTC
My patch for bug 4434 fixes this.
Comment 4 Walter Bright 2010-11-07 12:27:23 UTC

*** This issue has been marked as a duplicate of issue 4434 ***