{"action":"created","issue":{"url":"https://api.github.com/repos/nlohmann/json/issues/359","repository_url":"https://api.github.com/repos/nlohmann/json","labels_url":"https://api.github.com/repos/nlohmann/json/issues/359/labels{/name}","comments_url":"https://api.github.com/repos/nlohmann/json/issues/359/comments","events_url":"https://api.github.com/repos/nlohmann/json/issues/359/events","html_url":"https://github.com/nlohmann/json/issues/359","id":189706553,"number":359,"title":"Crash in dump() from a static object","user":{"login":"palacaze","id":1309100,"avatar_url":"https://avatars.githubusercontent.com/u/1309100?v=3","gravatar_id":"","url":"https://api.github.com/users/palacaze","html_url":"https://github.com/palacaze","followers_url":"https://api.github.com/users/palacaze/followers","following_url":"https://api.github.com/users/palacaze/following{/other_user}","gists_url":"https://api.github.com/users/palacaze/gists{/gist_id}","starred_url":"https://api.github.com/users/palacaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palacaze/subscriptions","organizations_url":"https://api.github.com/users/palacaze/orgs","repos_url":"https://api.github.com/users/palacaze/repos","events_url":"https://api.github.com/users/palacaze/events{/privacy}","received_events_url":"https://api.github.com/users/palacaze/received_events","type":"User","site_admin":false},"labels":[{"id":46374231,"url":"https://api.github.com/repos/nlohmann/json/labels/kind:%20bug","name":"kind: bug","color":"fc2929","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":18,"created_at":"2016-11-16T13:39:52Z","updated_at":"2016-11-21T22:02:01Z","closed_at":null,"body":"Change 29c5f32d4287a49f59fcd65b7ffacd7f154b03aa from the performance regression bug #272 introduces a potential crash in dump(). This has to do with deinitialization order of static objects.\r\n\r\nThe following code (not json specific) reproduces the problem (tested on GNU/Linux 64 bits with GCC 5.4):\r\n\r\n```cpp\r\n#include <locale>\r\n#include <sstream>\r\n#include <iostream>\r\n\r\nnamespace {\r\nstruct DecimalSeparator : std::numpunct<char> {\r\n    char do_decimal_point() const { return '.'; }\r\n};\r\n}\r\n\r\nstruct test {\r\n    void dump() {\r\n        std::stringstream ss;\r\n        const static std::locale loc(std::locale(), new DecimalSeparator);\r\n        ss.imbue(loc);\r\n        ss << \"test \" << 1.0;\r\n        std::cout << ss.str() << std::endl;\r\n    }\r\n    ~test() {\r\n        dump();\r\n    }\r\n};\r\n\r\nstatic test t;\r\n\r\nint main() {\r\n    t.dump();\r\n    return 0;\r\n}\r\n```\r\n\r\nWhat happens here it that the static test is initialized first, then the first call to dump() creates the static locale object. When we leave main(), the static locale gets destroyed first (reversed initialization order), then the static test object is destructed, thus calling the destructor, which so happens to call dump() whose static object is no longer valid.\r\n\r\nRemoving the static keyword introduced in commit 29c5f32d4287a49f59fcd65b7ffacd7f154b03aa fixes the crash."},"comment":{"url":"https://api.github.com/repos/nlohmann/json/issues/comments/262081580","html_url":"https://github.com/nlohmann/json/issues/359#issuecomment-262081580","issue_url":"https://api.github.com/repos/nlohmann/json/issues/359","id":262081580,"user":{"login":"palacaze","id":1309100,"avatar_url":"https://avatars.githubusercontent.com/u/1309100?v=3","gravatar_id":"","url":"https://api.github.com/users/palacaze","html_url":"https://github.com/palacaze","followers_url":"https://api.github.com/users/palacaze/followers","following_url":"https://api.github.com/users/palacaze/following{/other_user}","gists_url":"https://api.github.com/users/palacaze/gists{/gist_id}","starred_url":"https://api.github.com/users/palacaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palacaze/subscriptions","organizations_url":"https://api.github.com/users/palacaze/orgs","repos_url":"https://api.github.com/users/palacaze/repos","events_url":"https://api.github.com/users/palacaze/events{/privacy}","received_events_url":"https://api.github.com/users/palacaze/received_events","type":"User","site_admin":false},"created_at":"2016-11-21T22:02:01Z","updated_at":"2016-11-21T22:02:01Z","body":"I can't reproduce the crash with this change, so as far as I am concerned the bug has been fixed."}}
{"actor":{"display_login":"palacaze"}}