D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15274 - typeid(this) inside of an interface contract segfaults
Summary: typeid(this) inside of an interface contract segfaults
Status: RESOLVED DUPLICATE of issue 7517
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-02 16:14 UTC by Alex Parrill
Modified: 2015-11-03 12:44 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Alex Parrill 2015-11-02 16:14:37 UTC
Example code:

	interface MyFace {
		Object bar()
		out(v) {
			assert(typeid(this));
		}
	}

	class MyClass : MyFace {
		override Object bar() {
			return new MyClass();
		}
	}

	void main() {
		(new MyClass()).bar();
	}

This code causes a segfault when ran. Removing the `assert(typeid(this))` line causes the error to go away. Putting the out contract on the class also does not cause an error.

GDB output:

(gdb) bt
#0  0x000000000041f3d9 in invariant._d_invariant() ()
#1  0x000000000041dbd4 in test.MyFace.bar() (this=0x7fffffffdca8, 
    v=@0x7fffffffdca0: 0x7ffff7ed0020) at ./test.d:5
#2  0x000000000041dc45 in test.MyClass.bar() (this=0x7ffff7ed0000)
    at ./test.d:10
#3  0x000000000041dc80 in D main () at ./test.d:16
#4  0x000000000041f35f in rt.dmain2._d_run_main() ()
#5  0x000000000041f2ba in rt.dmain2._d_run_main() ()
#6  0x000000000041f31b in rt.dmain2._d_run_main() ()
#7  0x000000000041f2ba in rt.dmain2._d_run_main() ()
#8  0x000000000041f23a in _d_run_main ()
#9  0x000000000041dd28 in main ()

Version:

> dmd --version
DMD64 D Compiler v2.068.2
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
Comment 1 Kenji Hara 2015-11-03 12:44:31 UTC

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