Thread overview
dmd segmentation fault with duplicate class definition
Mar 29, 2018
number
Mar 29, 2018
Jonathan M Davis
Mar 29, 2018
Seb
Mar 30, 2018
number
Mar 30, 2018
LiNbO3
March 29, 2018
I'm learning, so no idea if this is known or what causes the segfault.

Linux
DMD64 D Compiler v2.078.3

```
void main()
{
	import std.stdio;
	
	{
		class C
		{
			int i;
		}
	}
	{
		class C
		{
			int i;
		}
		C c1 = new C();
		c1.i++;          // no segfault without this line
		C c2 = c1;
	}
}
```

dmd -run test.d
test.d(12): Error: declaration C is already defined in another scope in main
test.d(16): Error: class C no size because of forward reference
test.d(12): Error: class C is forward referenced when looking for 'i'
test.d(12): Error: class C is forward referenced when looking for 'i'
test.d(12): Error: class C is forward referenced when looking for 'opDot'
test.d(12): Error: class C is forward referenced when looking for 'opDispatch'
Segmentation fault (core dumped)


March 29, 2018
On Thursday, March 29, 2018 20:48:47 number via Digitalmars-d wrote:
> I'm learning, so no idea if this is known or what causes the segfault.

If you cannot find the issue https://issues.dlang.org, then report it. Worst case, if there was a matching report that you missed, then the new issue will be closed as a duplicate. Either way, the compiler should never segfault.

- Jonathan M Davis

March 29, 2018
On Thursday, 29 March 2018 at 20:48:47 UTC, number wrote:
> I'm learning, so no idea if this is known or what causes the segfault.
>
> [...]

Always try the latest release when you run into an ICE - chances are very good that it already has been fixed:

https://run.dlang.io/is/OySBGO
March 30, 2018
On Thursday, 29 March 2018 at 21:18:02 UTC, Seb wrote:
> On Thursday, 29 March 2018 at 20:48:47 UTC, number wrote:
>> I'm learning, so no idea if this is known or what causes the segfault.
>>
>> [...]
>
> Always try the latest release when you run into an ICE - chances are very good that it already has been fixed:
>
> https://run.dlang.io/is/OySBGO

the provoking line is commented out in that snippet. when commented in, all compilers give the segfault, including ldc ones. except for 'all dmd compilers..' with version <= 2.066.0
March 30, 2018
On Thursday, 29 March 2018 at 21:18:02 UTC, Seb wrote:
> On Thursday, 29 March 2018 at 20:48:47 UTC, number wrote:
>> I'm learning, so no idea if this is known or what causes the segfault.
>>
>> [...]
>
> Always try the latest release when you run into an ICE - chances are very good that it already has been fixed:
>
> https://run.dlang.io/is/OySBGO

There are a couple of bugs here:

---
void main()
{
    { class C { } }
    class C { }
    // C x; x.x=1;
    // static assert (!__traits(compiles, C.x));
}
---

The first bug can be shown by de-commenting the first line and can be easily solved by modifying hdrgen.d by adding a check on t.sym.parent being non-null to the visit(TypeClass) method.
Once that's fixed de-comment the second line to have the compiler crash and burn somewhere else.