According to C++11 specification:
The results of including in a translation unit shall be as if defined an instance of ios_base::Init with static storage duration. Similarly, the entire program shall behave as if there were at least one instance of ios_base::Init with static storage duration
This implies that if my code looks like that:
// A.cpp
#include <iostream>
int foo() {
cerr << "bar";
return 42;
}
and
// B.cpp
namespace {
unsigned long testuj() {
int id = foo();
return id;
}
unsigned long id = testuj();
}
int main() {
return 0;
}
then I should be safe calling cerr without the risk of a static initialization fiasco.
Unfortunately, the code following code segfaults... Why? I don't think gcc 6.2.1 decided to ignore the C++11 specification.
Aucun commentaire:
Enregistrer un commentaire