Bug 57163 - Link failure with thread_local
Summary: Link failure with thread_local
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: c++-thread_local
  Show dependency treegraph
 
Reported: 2013-05-03 16:20 UTC by Joshua Leahy
Modified: 2014-01-30 15:25 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 4.9.0
Known to fail: 4.8.2
Last reconfirmed:


Attachments
Preprocessed input files (196.32 KB, application/octet-stream)
2013-05-03 16:20 UTC, Joshua Leahy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Leahy 2013-05-03 16:20:27 UTC
Created attachment 30026 [details]
Preprocessed input files

Output of gcc -v:
Thread model: posix
gcc version 4.8.0 (GCC)
Target: x86_64-unknown-linux-gnu

Input file test.cpp:
#include <random>
extern thread_local std::default_random_engine rng;
int main() { return rng(); }

Input file test2.cpp:
#include <random>
thread_local std::default_random_engine rng;

Command line and output:
g++ -std=c++11 -c test.cpp && g++ -std=c++11 -c test2.cpp && g++ -std=c++11 test.o test2.o
test.o:test.cpp:function _ZTW3rng: error: undefined reference to '_ZTH3rng'
collect2: error: ld returned 1 exit status

Complete preprocessed output attached. I can't reproduce this with a single translation unit.
Comment 1 Paolo Carlini 2013-05-04 00:07:33 UTC
In any case the actual std::default_random_engine doesn't play any special role: the same error happens including, as test.h, something like

namespace std
{
  struct default_random_engine
  {
    default_random_engine() { }

    int operator()() { return 1; }
  };
}
Comment 2 Marcel Meyer 2013-06-14 22:40:29 UTC
Confirmed for gcc 4.8.1.
Comment 3 Marcel Meyer 2013-06-14 22:41:45 UTC
Please have a look at bug #55800 .
Comment 4 Conrad S 2013-12-02 02:56:21 UTC
Confirmed for gcc 4.8.2
Comment 5 Richard Biener 2014-01-30 15:25:45 UTC
Works with 4.9 for me.