fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template<class T>
  6. struct bar {
  7. struct foo {
  8. foo () {
  9. cerr << "bar::foo" << endl;
  10. }
  11. int i = 42;
  12. };
  13.  
  14. void baz() {
  15. cerr << bar::FOO.i << endl;
  16. }
  17.  
  18. static thread_local foo FOO;
  19. };
  20.  
  21. struct far {
  22. struct foo {
  23. foo () {
  24. cerr << "far::foo" << endl;
  25. }
  26. int i = 42;
  27. };
  28.  
  29. void baz() {
  30. cerr << far::FOO.i << endl;
  31. }
  32.  
  33. static thread_local foo FOO;
  34. };
  35.  
  36. template<class T> thread_local typename bar<T>::foo bar<T>::FOO;
  37. thread_local typename far::foo far::FOO;
  38.  
  39. int main() {
  40. cerr << "main" << endl;
  41. bar<int> b;
  42. b.baz();
  43.  
  44. far f;
  45. f.baz();
  46. return 0;
  47. }
Success #stdin #stdout #stderr 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
main
0
far::foo
bar::foo
42