Perhaps best to get to the 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);
}
The above code (which I think is valid?) compiles okay if foo()
is not a template, however as it stands, this causes GCC to segfault. Probably is a compiler bug - but would like to know if I'm doing something wrong?
The idea is I want to execute something always when that function exits (even with an exception - unless there's a better way?)
I tested on coliru and locally with 5.2.1... Seems to compile fine on clang though.
Aucun commentaire:
Enregistrer un commentaire