{"action":"created","issue":{"url":"https://api.github.com/repos/stlab/adobe_source_libraries/issues/49","repository_url":"https://api.github.com/repos/stlab/adobe_source_libraries","labels_url":"https://api.github.com/repos/stlab/adobe_source_libraries/issues/49/labels{/name}","comments_url":"https://api.github.com/repos/stlab/adobe_source_libraries/issues/49/comments","events_url":"https://api.github.com/repos/stlab/adobe_source_libraries/issues/49/events","html_url":"https://github.com/stlab/adobe_source_libraries/issues/49","id":140866373,"number":49,"title":"Forest constructor exception safety","user":{"login":"ahmedcharles","id":3112514,"avatar_url":"https://avatars.githubusercontent.com/u/3112514?v=3","gravatar_id":"","url":"https://api.github.com/users/ahmedcharles","html_url":"https://github.com/ahmedcharles","followers_url":"https://api.github.com/users/ahmedcharles/followers","following_url":"https://api.github.com/users/ahmedcharles/following{/other_user}","gists_url":"https://api.github.com/users/ahmedcharles/gists{/gist_id}","starred_url":"https://api.github.com/users/ahmedcharles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahmedcharles/subscriptions","organizations_url":"https://api.github.com/users/ahmedcharles/orgs","repos_url":"https://api.github.com/users/ahmedcharles/repos","events_url":"https://api.github.com/users/ahmedcharles/events{/privacy}","received_events_url":"https://api.github.com/users/ahmedcharles/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-03-15T04:08:14Z","updated_at":"2016-03-20T17:54:40Z","closed_at":"2016-03-15T08:12:45Z","body":"The code below does the same test with both forest and list. They should produce the same output, but they don't, because the forest copy constructor does not handle exceptions appropriately.\r\n\r\n```\r\n#include \"adobe/forest.hpp\"\r\n\r\n#include <iostream>\r\n#include <list>\r\n\r\nbool activate = false;\r\n\r\nclass test {\r\npublic:\r\n  test(int d) : data_(d) { std::cout << \"create \" << data_ << std::endl; }\r\n  test(const test& o) : data_(o.data_) {\r\n    std::cout << \"copy c \" << data_ << std::endl;\r\n    if (activate && data_ == 2) {\r\n      std::cout << \"throw \" << data_ << std::endl;\r\n      throw 0;\r\n    }\r\n  }\r\n  test& operator=(const test& o) {\r\n    data_ = o.data_;\r\n    std::cout << \"copy = \" << data_ << std::endl;\r\n    return *this;\r\n  }\r\n  ~test() { std::cout << \"delete \" << data_ << std::endl; }\r\nprivate:\r\n  friend std::ostream& operator<<(std::ostream& out, const test& o);\r\n\r\n  int data_;\r\n};\r\n\r\nstd::ostream& operator<<(std::ostream& out, const test& o) {\r\n  out << o.data_;\r\n  return out;\r\n}\r\n\r\ntemplate<class T>\r\nvoid x() try {\r\n  using forest = T;\r\n\r\n  forest f1;\r\n  f1.push_back(1);\r\n  f1.push_back(2);\r\n  f1.push_back(3);\r\n\r\n  activate = true;\r\n\r\n  forest f(f1);\r\n} catch(...) { activate = false; }\r\n\r\nint main() {\r\n  std::cout << \"adobe::forest\" << std::endl;\r\n  x<adobe::forest<test>>();\r\n  std::cout << \"std::list\" << std::endl;\r\n  x<std::list<test>>();\r\n}\r\n```\r\n\r\n\r\n```\r\nadobe::forest\r\ncreate 1\r\ncopy c 1\r\ndelete 1\r\ncreate 2\r\ncopy c 2\r\ndelete 2\r\ncreate 3\r\ncopy c 3\r\ndelete 3\r\ncopy c 1 // never gets deleted below.\r\ncopy c 2\r\nthrow 2\r\ndelete 1\r\ndelete 2\r\ndelete 3\r\nstd::list\r\ncreate 1\r\ncopy c 1\r\ndelete 1\r\ncreate 2\r\ncopy c 2\r\ndelete 2\r\ncreate 3\r\ncopy c 3\r\ndelete 3\r\ncopy c 1\r\ncopy c 2\r\nthrow 2\r\ndelete 1\r\ndelete 1\r\ndelete 2\r\ndelete 3\r\n```"},"comment":{"url":"https://api.github.com/repos/stlab/adobe_source_libraries/issues/comments/198974408","html_url":"https://github.com/stlab/adobe_source_libraries/issues/49#issuecomment-198974408","issue_url":"https://api.github.com/repos/stlab/adobe_source_libraries/issues/49","id":198974408,"user":{"login":"sean-parent","id":2279724,"avatar_url":"https://avatars.githubusercontent.com/u/2279724?v=3","gravatar_id":"","url":"https://api.github.com/users/sean-parent","html_url":"https://github.com/sean-parent","followers_url":"https://api.github.com/users/sean-parent/followers","following_url":"https://api.github.com/users/sean-parent/following{/other_user}","gists_url":"https://api.github.com/users/sean-parent/gists{/gist_id}","starred_url":"https://api.github.com/users/sean-parent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sean-parent/subscriptions","organizations_url":"https://api.github.com/users/sean-parent/orgs","repos_url":"https://api.github.com/users/sean-parent/repos","events_url":"https://api.github.com/users/sean-parent/events{/privacy}","received_events_url":"https://api.github.com/users/sean-parent/received_events","type":"User","site_admin":false},"created_at":"2016-03-20T17:54:40Z","updated_at":"2016-03-20T17:54:40Z","body":"Will look at that. Travis is currently complaining about Eve's use of\nforest iterators with an incomplete type. Not certain why my changes broke\nthat but haven't had time to look deeply.\nSean\n\nOn Sun, Mar 20, 2016 at 6:12 AM, Ahmed Charles <notifications@github.com>\nwrote:\n\n> One more issue. The change you made to the default constructor forest() =\n> default; results in size_m being default initialized rather than value\n> initialized, which means it is uninitialized...\n>\n> —\n> You are receiving this because you modified the open/close state.\n> Reply to this email directly or view it on GitHub\n> <https://github.com/stlab/adobe_source_libraries/issues/49#issuecomment-198929327>\n>\n"}}