#include <iostream>
using namespace std;
template<class T>
struct bar {
struct foo {
foo () {
cerr << "bar::foo" << endl;
}
int i = 42;
};
void baz() {
cerr << bar::FOO.i << endl;
}
static thread_local foo FOO;
};
struct far {
struct foo {
foo () {
cerr << "far::foo" << endl;
}
int i = 42;
};
void baz() {
cerr << far::FOO.i << endl;
}
static thread_local foo FOO;
};
template<class T> thread_local typename bar<T>::foo bar<T>::FOO;
thread_local typename far::foo far::FOO;
int main() {
cerr << "main" << endl;
bar<int> b;
b.baz();
far f;
f.baz();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlPGNsYXNzIFQ+CnN0cnVjdCBiYXIgewogICAgc3RydWN0IGZvbyB7CiAgICAgICAgZm9vICgpIHsKICAgICAgICAgICAgY2VyciA8PCAiYmFyOjpmb28iIDw8IGVuZGw7CiAgICAgICAgfQogICAgICAgIGludCBpID0gNDI7CiAgICB9OwoKICAgIHZvaWQgYmF6KCkgewogICAgICAgIGNlcnIgPDwgYmFyOjpGT08uaSA8PCBlbmRsOwogICAgfQoKICAgIHN0YXRpYyB0aHJlYWRfbG9jYWwgZm9vIEZPTzsKfTsKCnN0cnVjdCBmYXIgewogICAgc3RydWN0IGZvbyB7CiAgICAgICAgZm9vICgpIHsKICAgICAgICAgICAgY2VyciA8PCAiZmFyOjpmb28iIDw8IGVuZGw7CiAgICAgICAgfQogICAgICAgIGludCBpID0gNDI7CiAgICB9OwoKICAgIHZvaWQgYmF6KCkgewogICAgICAgIGNlcnIgPDwgZmFyOjpGT08uaSA8PCBlbmRsOwogICAgfQoKICAgIHN0YXRpYyB0aHJlYWRfbG9jYWwgZm9vIEZPTzsKfTsKCnRlbXBsYXRlPGNsYXNzIFQ+IHRocmVhZF9sb2NhbCB0eXBlbmFtZSBiYXI8VD46OmZvbyBiYXI8VD46OkZPTzsKdGhyZWFkX2xvY2FsIHR5cGVuYW1lIGZhcjo6Zm9vIGZhcjo6Rk9POwoKaW50IG1haW4oKSB7CiAgICBjZXJyIDw8ICJtYWluIiA8PCBlbmRsOwogICAgYmFyPGludD4gYjsKICAgIGIuYmF6KCk7CiAgICAKICAgIGZhciBmOwogICAgZi5iYXooKTsKICAgIHJldHVybiAwOwp9