[Bug c++/60702] New: thread_local initialization

2014-03-28 Thread dv.main at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60702

Bug ID: 60702
   Summary: thread_local initialization
   Product: gcc
   Version: 4.8.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dv.main at gmail dot com

Created attachment 32480
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32480&action=edit
Gcc verbose output

Invalid thread local object initialization.
Snippet:

#include 

using namespace std;

struct far {
struct boo {
boo () {
cerr << "bar::boo" << endl;
}
int i = 42;
};

static void baz() {
cerr << far::FOO.i << endl;
}

static thread_local boo FOO;
};

thread_local typename far::boo far::FOO;

int main() {
far f;
cerr << f.FOO.i << endl;
cerr << far::FOO.i << endl;
return 0;
}

Output:
0
bar::boo
42


[Bug c++/60702] thread_local initialization

2014-03-28 Thread dv.main at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60702

--- Comment #2 from Stan Pavlovski  ---
Created attachment 32482
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32482&action=edit
Source file


[Bug c++/60702] thread_local initialization

2014-03-28 Thread dv.main at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60702

--- Comment #1 from Stan Pavlovski  ---
Created attachment 32481
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32481&action=edit
Gcc temp output


[Bug c++/60702] thread_local initialization

2014-03-28 Thread dv.main at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60702

--- Comment #3 from Stan Pavlovski  ---
Template class' thread_local member is not initialized unless other
non-template class' thread_local member is initialized first:

#include 

using namespace std;

struct far {
struct boo {
boo () {
cerr << "far::boo" << endl;
}
int i = 42;
};

static void baz() {
cerr << far::FOO.i << endl;
}

static thread_local boo FOO;
};

template
struct bar {
struct foo {
foo () {
cerr << "bar::foo" << endl;
}
int i = 42;
};

void baz() {
cerr << bar::FOO.i << endl;
}

static thread_local foo FOO;
};

template thread_local typename bar::foo bar::FOO;
thread_local typename far::boo far::FOO;

int main() {
bar b;
b.baz();

far f;
f.baz();
return 0;
}

Output:

0
far::boo
bar::foo
42