https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69593

            Bug ID: 69593
           Summary: static thread_local in a structure within a function
                    template causes segfault
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thenim at gmail dot com
  Target Milestone: ---

I think it's perhaps best demonstrated by bit of code:

#include <iostream>
#include <vector>

using namespace std;

struct A {
    template <typename T>
    void foo(T& f) {
        struct auto_logger {
            ~auto_logger() {
                static thread_local vector<char> b; // Segfault here
            }
        } inst;
    }
};

int main(void) {
    A a;
    vector<char> b;
    a.foo(b);
}

This will compile (and run fine) if the function foo() is not a template.

Reply via email to