Variable templates and std::cout — order of construction
问题 It looks like we can safely use std::cout object in constructors of objects with static storage duration as stated in this question. However, I'm not entirely sure that we can safely use them in case of variable templates: #include <iostream> template<class T> T x = T{}; void foo() { class Test { public: Test() { std::cout << "Test::Test\n"; } }; Test t = x<Test>; } int main() { std::cout << "main\n"; } This code crashes in clang (live example) and I'm not sure whether it's a bug or not. 回答1: