{"action":"created","issue":{"url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/3761","labels_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/3761/labels{/name}","comments_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/3761/comments","events_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/3761/events","html_url":"https://github.com/D-Programming-Language/dmd/pull/3761","id":37792306,"number":3761,"title":"Issue 13116: should reject returning `this` from a ref class member function","user":{"login":"quickfur","id":405446,"avatar_url":"https://avatars.githubusercontent.com/u/405446?v=3","gravatar_id":"","url":"https://api.github.com/users/quickfur","html_url":"https://github.com/quickfur","followers_url":"https://api.github.com/users/quickfur/followers","following_url":"https://api.github.com/users/quickfur/following{/other_user}","gists_url":"https://api.github.com/users/quickfur/gists{/gist_id}","starred_url":"https://api.github.com/users/quickfur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quickfur/subscriptions","organizations_url":"https://api.github.com/users/quickfur/orgs","repos_url":"https://api.github.com/users/quickfur/repos","events_url":"https://api.github.com/users/quickfur/events{/privacy}","received_events_url":"https://api.github.com/users/quickfur/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2014-07-14T14:41:04Z","updated_at":"2015-03-09T12:41:05Z","closed_at":"2014-08-05T14:59:09Z","pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/dmd/pulls/3761","html_url":"https://github.com/D-Programming-Language/dmd/pull/3761","diff_url":"https://github.com/D-Programming-Language/dmd/pull/3761.diff","patch_url":"https://github.com/D-Programming-Language/dmd/pull/3761.patch"},"body":"Fixes: https://issues.dlang.org/show_bug.cgi?id=13116\r\nBasically, for class members, `this` is a local reference to the class instance, so returning it by ref amounts to returning a reference to a local variable (due to classes being reference types).\r\nFor structs, returning `this` by ref returns the address of the original struct, so there is no problem.\r\nThere is an unresolved issue with this fix, though: the following valid case is now rejected:\r\n````\r\nclass C {\r\n    void func() {\r\n        ref C helper() {\r\n            return this; // should be OK\r\n        }\r\n        auto tmp = helper(); // reference hasn't escaped, shouldn't be rejected\r\n    }\r\n}\r\n````\r\nNot sure how to fix this. Any pointers from dmd experts? ;-)"},"comment":{"url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/comments/77845966","html_url":"https://github.com/D-Programming-Language/dmd/pull/3761#issuecomment-77845966","issue_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/3761","id":77845966,"user":{"login":"9rnsr","id":254394,"avatar_url":"https://avatars.githubusercontent.com/u/254394?v=3","gravatar_id":"","url":"https://api.github.com/users/9rnsr","html_url":"https://github.com/9rnsr","followers_url":"https://api.github.com/users/9rnsr/followers","following_url":"https://api.github.com/users/9rnsr/following{/other_user}","gists_url":"https://api.github.com/users/9rnsr/gists{/gist_id}","starred_url":"https://api.github.com/users/9rnsr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/9rnsr/subscriptions","organizations_url":"https://api.github.com/users/9rnsr/orgs","repos_url":"https://api.github.com/users/9rnsr/repos","events_url":"https://api.github.com/users/9rnsr/events{/privacy}","received_events_url":"https://api.github.com/users/9rnsr/received_events","type":"User","site_admin":false},"created_at":"2015-03-09T12:41:04Z","updated_at":"2015-03-09T12:41:04Z","body":"I don't understand. Are you saying that we cannot fix compiler bug anymore so it will break user code?"}}