{"action":"created","comment":{"url":"https://api.github.com/repos/dlang/phobos/pulls/comments/64554672","id":64554672,"diff_hunk":"@@ -1123,48 +1123,107 @@ allocated with the same allocator.\n */\n void dispose(A, T)(auto ref A alloc, T* p)\n {\n+    if (!p) return;\n     static if (hasElaborateDestructor!T)\n-    {\n-        destroy(*p);\n-    }\n+        p.__dtor;\n     alloc.deallocate((cast(void*)p)[0 .. T.sizeof]);\n }\n \n /// Ditto\n void dispose(A, T)(auto ref A alloc, T p)\n-if (is(T == class) || is(T == interface))\n+if (is(T == class) && T.stringof != Object.stringof)\n+{\n+    if (!p) return;\n+    auto support = (cast(void*) p)[0 .. typeid(p).initializer.length];\n+    static if (__traits(hasMember, T, \"__dtor\"))\n+        p.__dtor;\n+    alloc.deallocate(support);\n+}\n+\n+/// Ditto\n+void dispose(A, T, bool isObject = false)(auto ref A alloc, T p)\n+if (is(T == class) && T.stringof == Object.stringof)\n {\n+    // the content of this overload can't be in the previous because when the\n+    // static type is not known (e.g after cast from interface to Object) dispose()\n+    // can't be @nogc since the dtor is a delegate determined at runtime. isObject\n+    // indicates if the static type is really \"Object\", e.g \"alloc.make!Object\"\n     if (!p) return;\n-    static if (is(T == interface))\n+    static if (!isObject)\n     {\n-        version(Windows)\n+        TypeInfo_Class tic = cast(TypeInfo_Class) typeid(p);\n+        auto support = (cast(void*) p)[0 .. tic.initializer.length];\n+\n+        void* dtorPtr = tic.destructor;\n+        while (!dtorPtr && tic.base)\n         {\n-            import core.sys.windows.unknwn;\n-            static assert(!is(T: IUnknown), \"COM interfaces can't be destroyed in \"\n-                ~ __PRETTY_FUNCTION__);\n+            tic = tic.base;\n+            dtorPtr = tic.destructor;\n+        }\n+        if (dtorPtr)\n+        {\n+            void delegate() dtor;\n+            dtor.funcptr = cast(void function()) dtorPtr;\n+            dtor.ptr = cast(void*) p;\n+            dtor();\n         }\n-        auto ob = cast(Object) p;\n     }\n-    else\n-        alias ob = p;\n-    auto support = (cast(void*) ob)[0 .. typeid(ob).initializer.length];\n-    destroy(p);\n     alloc.deallocate(support);\n }\n \n /// Ditto\n+void dispose(A, T)(auto ref A alloc, T p)\n+if (is(T == interface))\n+{\n+    if (!p) return;\n+    version(Windows)\n+    {\n+        import core.sys.windows.unknwn: IUnknown;\n+        static assert(!is(T: IUnknown), \"COM interfaces can't be destroyed in \"\n+            ~ __PRETTY_FUNCTION__);\n+    }\n+    static if (__traits(allMembers, T).length)\n+    {\n+        foreach (ov; __traits(getOverloads, T, __traits(allMembers, T)[0]))\n+        static assert(functionLinkage!ov != \"C++\", \"C++ interfaces can't be destroyed in \"\n+            ~ __PRETTY_FUNCTION__);\n+    }\n+    dispose(alloc, cast(Object) p);\n+}\n+\n+/// Ditto\n void dispose(A, T)(auto ref A alloc, T[] array)\n {\n     static if (hasElaborateDestructor!(typeof(array[0])))","path":"std/experimental/allocator/package.d","position":89,"original_position":89,"commit_id":"72dc6a75842805ec67a2541b6bc1d6f6d70a6a43","original_commit_id":"72dc6a75842805ec67a2541b6bc1d6f6d70a6a43","user":{"login":"BBasile","id":16154339,"avatar_url":"https://avatars.githubusercontent.com/u/16154339?v=3","gravatar_id":"","url":"https://api.github.com/users/BBasile","html_url":"https://github.com/BBasile","followers_url":"https://api.github.com/users/BBasile/followers","following_url":"https://api.github.com/users/BBasile/following{/other_user}","gists_url":"https://api.github.com/users/BBasile/gists{/gist_id}","starred_url":"https://api.github.com/users/BBasile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BBasile/subscriptions","organizations_url":"https://api.github.com/users/BBasile/orgs","repos_url":"https://api.github.com/users/BBasile/repos","events_url":"https://api.github.com/users/BBasile/events{/privacy}","received_events_url":"https://api.github.com/users/BBasile/received_events","type":"User","site_admin":false},"body":"Otherwise the overload that handles the `@nogc` destructor would look like this\r\n\r\n```D\r\nvoid dispose(A, T)(auto ref A alloc, T p)\r\nif (is(T == class) && T.stringof != Object.stringof)\r\n{\r\n    if (!p) return;\r\n    auto support = (cast(void*) p)[0 .. typeid(p).initializer.length];\r\n    static if (__traits(hasMember, T, \"__dtor\"))\r\n        p.__dtor;\r\n    else\r\n    {\r\n        TypeInfo_Class tic = cast(TypeInfo_Class) typeid(p);\r\n        void* dtorPtr = tic.destructor;\r\n        while (!dtorPtr && tic.base)\r\n        {\r\n            tic = tic.base;\r\n            dtorPtr = tic.destructor;\r\n        }\r\n        if (tic && tic.destructor)\r\n        {\r\n            dispose(alloc, cast(Object) p);\r\n            return;\r\n        }\r\n    }\r\n    alloc.deallocate(support);\r\n}\u0000\r\n```\r\n\r\nnot good.","created_at":"2016-05-25T11:13:29Z","updated_at":"2016-05-25T11:13:29Z","html_url":"https://github.com/dlang/phobos/pull/4351#discussion_r64554672","pull_request_url":"https://api.github.com/repos/dlang/phobos/pulls/4351","_links":{"self":{"href":"https://api.github.com/repos/dlang/phobos/pulls/comments/64554672"},"html":{"href":"https://github.com/dlang/phobos/pull/4351#discussion_r64554672"},"pull_request":{"href":"https://api.github.com/repos/dlang/phobos/pulls/4351"}}},"pull_request":{"url":"https://api.github.com/repos/dlang/phobos/pulls/4351","id":71248827,"html_url":"https://github.com/dlang/phobos/pull/4351","diff_url":"https://github.com/dlang/phobos/pull/4351.diff","patch_url":"https://github.com/dlang/phobos/pull/4351.patch","issue_url":"https://api.github.com/repos/dlang/phobos/issues/4351","number":4351,"state":"open","locked":false,"title":"fix issue 16064 - std.experimental.allocator.dispose can't be used in @nogc blocks","user":{"login":"BBasile","id":16154339,"avatar_url":"https://avatars.githubusercontent.com/u/16154339?v=3","gravatar_id":"","url":"https://api.github.com/users/BBasile","html_url":"https://github.com/BBasile","followers_url":"https://api.github.com/users/BBasile/followers","following_url":"https://api.github.com/users/BBasile/following{/other_user}","gists_url":"https://api.github.com/users/BBasile/gists{/gist_id}","starred_url":"https://api.github.com/users/BBasile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BBasile/subscriptions","organizations_url":"https://api.github.com/users/BBasile/orgs","repos_url":"https://api.github.com/users/BBasile/repos","events_url":"https://api.github.com/users/BBasile/events{/privacy}","received_events_url":"https://api.github.com/users/BBasile/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-24T16:10:00Z","updated_at":"2016-05-25T11:13:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2f67538ddc3de745ba225d31e45f8e156878cf1f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dlang/phobos/pulls/4351/commits","review_comments_url":"https://api.github.com/repos/dlang/phobos/pulls/4351/comments","review_comment_url":"https://api.github.com/repos/dlang/phobos/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dlang/phobos/issues/4351/comments","statuses_url":"https://api.github.com/repos/dlang/phobos/statuses/72dc6a75842805ec67a2541b6bc1d6f6d70a6a43","head":{"label":"BBasile:issue-16064","ref":"issue-16064","sha":"72dc6a75842805ec67a2541b6bc1d6f6d70a6a43","user":{"login":"BBasile","id":16154339,"avatar_url":"https://avatars.githubusercontent.com/u/16154339?v=3","gravatar_id":"","url":"https://api.github.com/users/BBasile","html_url":"https://github.com/BBasile","followers_url":"https://api.github.com/users/BBasile/followers","following_url":"https://api.github.com/users/BBasile/following{/other_user}","gists_url":"https://api.github.com/users/BBasile/gists{/gist_id}","starred_url":"https://api.github.com/users/BBasile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BBasile/subscriptions","organizations_url":"https://api.github.com/users/BBasile/orgs","repos_url":"https://api.github.com/users/BBasile/repos","events_url":"https://api.github.com/users/BBasile/events{/privacy}","received_events_url":"https://api.github.com/users/BBasile/received_events","type":"User","site_admin":false},"repo":{"id":47467512,"name":"phobos","full_name":"BBasile/phobos","owner":{"login":"BBasile","id":16154339,"avatar_url":"https://avatars.githubusercontent.com/u/16154339?v=3","gravatar_id":"","url":"https://api.github.com/users/BBasile","html_url":"https://github.com/BBasile","followers_url":"https://api.github.com/users/BBasile/followers","following_url":"https://api.github.com/users/BBasile/following{/other_user}","gists_url":"https://api.github.com/users/BBasile/gists{/gist_id}","starred_url":"https://api.github.com/users/BBasile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BBasile/subscriptions","organizations_url":"https://api.github.com/users/BBasile/orgs","repos_url":"https://api.github.com/users/BBasile/repos","events_url":"https://api.github.com/users/BBasile/events{/privacy}","received_events_url":"https://api.github.com/users/BBasile/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/BBasile/phobos","description":"The standard library of the D programming language","fork":true,"url":"https://api.github.com/repos/BBasile/phobos","forks_url":"https://api.github.com/repos/BBasile/phobos/forks","keys_url":"https://api.github.com/repos/BBasile/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BBasile/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BBasile/phobos/teams","hooks_url":"https://api.github.com/repos/BBasile/phobos/hooks","issue_events_url":"https://api.github.com/repos/BBasile/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/BBasile/phobos/events","assignees_url":"https://api.github.com/repos/BBasile/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/BBasile/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/BBasile/phobos/tags","blobs_url":"https://api.github.com/repos/BBasile/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BBasile/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BBasile/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/BBasile/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BBasile/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/BBasile/phobos/languages","stargazers_url":"https://api.github.com/repos/BBasile/phobos/stargazers","contributors_url":"https://api.github.com/repos/BBasile/phobos/contributors","subscribers_url":"https://api.github.com/repos/BBasile/phobos/subscribers","subscription_url":"https://api.github.com/repos/BBasile/phobos/subscription","commits_url":"https://api.github.com/repos/BBasile/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/BBasile/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/BBasile/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/BBasile/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/BBasile/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/BBasile/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BBasile/phobos/merges","archive_url":"https://api.github.com/repos/BBasile/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BBasile/phobos/downloads","issues_url":"https://api.github.com/repos/BBasile/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/BBasile/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/BBasile/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/BBasile/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BBasile/phobos/labels{/name}","releases_url":"https://api.github.com/repos/BBasile/phobos/releases{/id}","deployments_url":"https://api.github.com/repos/BBasile/phobos/deployments","created_at":"2015-12-05T18:26:16Z","updated_at":"2016-01-24T04:34:45Z","pushed_at":"2016-05-24T19:20:56Z","git_url":"git://github.com/BBasile/phobos.git","ssh_url":"git@github.com:BBasile/phobos.git","clone_url":"https://github.com/BBasile/phobos.git","svn_url":"https://github.com/BBasile/phobos","homepage":"dlang.org/phobos","size":49881,"stargazers_count":0,"watchers_count":0,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dlang:master","ref":"master","sha":"2f124dee5dadf80654ab5165ab6e21bdb8200819","user":{"login":"dlang","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/dlang","html_url":"https://github.com/dlang","followers_url":"https://api.github.com/users/dlang/followers","following_url":"https://api.github.com/users/dlang/following{/other_user}","gists_url":"https://api.github.com/users/dlang/gists{/gist_id}","starred_url":"https://api.github.com/users/dlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlang/subscriptions","organizations_url":"https://api.github.com/users/dlang/orgs","repos_url":"https://api.github.com/users/dlang/repos","events_url":"https://api.github.com/users/dlang/events{/privacy}","received_events_url":"https://api.github.com/users/dlang/received_events","type":"Organization","site_admin":false},"repo":{"id":1257084,"name":"phobos","full_name":"dlang/phobos","owner":{"login":"dlang","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/dlang","html_url":"https://github.com/dlang","followers_url":"https://api.github.com/users/dlang/followers","following_url":"https://api.github.com/users/dlang/following{/other_user}","gists_url":"https://api.github.com/users/dlang/gists{/gist_id}","starred_url":"https://api.github.com/users/dlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlang/subscriptions","organizations_url":"https://api.github.com/users/dlang/orgs","repos_url":"https://api.github.com/users/dlang/repos","events_url":"https://api.github.com/users/dlang/events{/privacy}","received_events_url":"https://api.github.com/users/dlang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dlang/phobos","description":"The standard library of the D programming language","fork":false,"url":"https://api.github.com/repos/dlang/phobos","forks_url":"https://api.github.com/repos/dlang/phobos/forks","keys_url":"https://api.github.com/repos/dlang/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dlang/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dlang/phobos/teams","hooks_url":"https://api.github.com/repos/dlang/phobos/hooks","issue_events_url":"https://api.github.com/repos/dlang/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/dlang/phobos/events","assignees_url":"https://api.github.com/repos/dlang/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/dlang/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/dlang/phobos/tags","blobs_url":"https://api.github.com/repos/dlang/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dlang/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dlang/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/dlang/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dlang/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/dlang/phobos/languages","stargazers_url":"https://api.github.com/repos/dlang/phobos/stargazers","contributors_url":"https://api.github.com/repos/dlang/phobos/contributors","subscribers_url":"https://api.github.com/repos/dlang/phobos/subscribers","subscription_url":"https://api.github.com/repos/dlang/phobos/subscription","commits_url":"https://api.github.com/repos/dlang/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/dlang/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/dlang/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/dlang/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/dlang/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/dlang/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dlang/phobos/merges","archive_url":"https://api.github.com/repos/dlang/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dlang/phobos/downloads","issues_url":"https://api.github.com/repos/dlang/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/dlang/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/dlang/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/dlang/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dlang/phobos/labels{/name}","releases_url":"https://api.github.com/repos/dlang/phobos/releases{/id}","deployments_url":"https://api.github.com/repos/dlang/phobos/deployments","created_at":"2011-01-15T07:00:06Z","updated_at":"2016-05-25T06:55:46Z","pushed_at":"2016-05-25T10:49:29Z","git_url":"git://github.com/dlang/phobos.git","ssh_url":"git@github.com:dlang/phobos.git","clone_url":"https://github.com/dlang/phobos.git","svn_url":"https://github.com/dlang/phobos","homepage":"dlang.org/phobos","size":77802,"stargazers_count":715,"watchers_count":715,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":485,"mirror_url":null,"open_issues_count":98,"forks":485,"open_issues":98,"watchers":715,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dlang/phobos/pulls/4351"},"html":{"href":"https://github.com/dlang/phobos/pull/4351"},"issue":{"href":"https://api.github.com/repos/dlang/phobos/issues/4351"},"comments":{"href":"https://api.github.com/repos/dlang/phobos/issues/4351/comments"},"review_comments":{"href":"https://api.github.com/repos/dlang/phobos/pulls/4351/comments"},"review_comment":{"href":"https://api.github.com/repos/dlang/phobos/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dlang/phobos/pulls/4351/commits"},"statuses":{"href":"https://api.github.com/repos/dlang/phobos/statuses/72dc6a75842805ec67a2541b6bc1d6f6d70a6a43"}}}}
{"actor":{"display_login":"BBasile"}}