D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9685 - Context pointer of struct isn't copied when a closure is passed by alias
Summary: Context pointer of struct isn't copied when a closure is passed by alias
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: pull, wrong-code
: 10963 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-03-10 22:43 UTC by deadalnix
Modified: 2015-03-25 03:45 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 deadalnix 2013-03-10 22:43:49 UTC
module structfail;

auto get(alias fun)() {
	struct Foo {
		size_t data;

		@property
		auto clone() {
			return Foo(data);
		}
	}

	return Foo(0);
}

void main() {
	uint a = 42;
	auto bar = get!(() => a)();

	auto qux = bar.clone;

	import std.stdio;
	writeln("bar context pointer :", (cast(void**) &bar)[1]);
	writeln("qux context pointer :", (cast(void**) &qux)[1]);
}

qux have a garbage context pointer.
Comment 1 John Colvin 2015-02-16 14:52:59 UTC
Apparently this is a the same bug, see
http://forum.dlang.org/post/crhogpikareipbtyswhu@forum.dlang.org

import std.stdio;
struct MapResult(alias fun)
{
    @property int front() {return fun();}
    @property auto save() {return typeof(this)();}
}
void main()
{
    int ys_length = 4;
    auto dg = {return MapResult!({return ys_length;})();};
    writeln(dg().front); /* 4, correct */
    writeln(dg().save.front); /* garbage */
}
Comment 2 John Colvin 2015-02-16 15:02:11 UTC
This doesn't happen with ldc 0.15.1

Observed in dmd git HEAD, 2.066.1 and 2.065.0
Comment 4 github-bugzilla 2015-02-18 02:29:09 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7c7f173611f827572ce783e8941ea8e10aae58f4
fix Issue 9685 - Context pointer of struct isn't copied when a closure is passed by alias

https://github.com/D-Programming-Language/dmd/commit/e99cc05b0e61272d0d88759452d6887669555100
Merge pull request #4418 from 9rnsr/fix9685

Issue 9685 - Context pointer of struct isn't copied when a closure is passed by alias
Comment 5 github-bugzilla 2015-02-21 09:11:42 UTC
Commits pushed to https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7c7f173611f827572ce783e8941ea8e10aae58f4
fix Issue 9685 - Context pointer of struct isn't copied when a closure is passed by alias

https://github.com/D-Programming-Language/dmd/commit/e99cc05b0e61272d0d88759452d6887669555100
Merge pull request #4418 from 9rnsr/fix9685
Comment 6 Kenji Hara 2015-03-25 03:45:37 UTC
*** Issue 10963 has been marked as a duplicate of this issue. ***